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

KillerDogeAlt
  • 25
  • 1
  • 4

1 Answers1

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
});
johnny_mac
  • 1,801
  • 3
  • 20
  • 48