0

Previous post I will refer to later

I am making a Discord bot which uses MySQL, but that shouldn't matter, I am trying to do a blacklist database so users in it can't use my bot

This is what I got so far:

con.query("SELECT EXISTS( SELECT 1 FROM `blacklist` WHERE `id` = '"+message.author.id+"')", function(error, result, field) {
    if(error) throw error;
});

And this kinda works, this is my output

[ RowDataPacket {
'EXISTS( SELECT 1 FROM `blacklist` WHERE `id` = \'227090776172134400\')': 1 } ]

And the last digit works like a boolean, 1 if the row exists, 0 if it does not But my problem is, that I can't seem to figure out how to check if it's a zero or not because it's an object

1
  • Take a look at this answer on how to access the property of an object Commented Dec 29, 2017 at 18:17

1 Answer 1

0

Why can't you make the query string a variable that you can later query on. For example:

let conStr = "SELECT EXISTS( SELECT 1 FROM `blacklist` WHERE `id` = '"+message.author.id+"')";
con.query(conStr, function(error, result, field) {
    if(error) throw error;
    console.log(result[conStr]); //--> 1
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.