This code has something wrong with it: When I try to select based on Discord ID it doesn't return a result ([]
) and I cannot fix it. This is the entire section of code, it is bound to be error filled but I am trying my best.
Please be patient with me, this is my first project of this scale and there are about 6 sections of code similar to this. I don't know what to do and I don't understand why it keeps erroring.
This code is supposed to check the message for a number (in a function) and it needs to retrieve the flags associated with the given Discord ID. (This ID should NOT be the same as the MySQL ID) Then it should check the flags for the given flags, and if they are found it should send a message. It does NOT send this message. If it isn't found, it should add it to the database. It doesn't do this either.
if (ageCheck(msg.content.toLowerCase(), "8", "15")) {
try {
if (result.length > 1) {
if (result[1].flag in {
1: "P",
2: "S",
3: "YA",
4: "A"
}) {
msg.channel.send({
embed: {
color: "e74c3c",
author: {
name: bot.user.username
},
title: "WARNING",
description: "This user has claimed to be older in the past, proceed with extreme caution!",
timestamp: new Date(),
footer: {
text: "This bot is not 100% accurate and results may be flawed or incorrect."
}
}
});
} else {
var sql = `INSERT IGNORE INTO pedodb (id, flag) VALUES ('${msg.author.id}', 'M')`;
con.query(sql, function (err) {
if (err) throw err;
console.log("Database Updated: Minor Added")
});
}
}
} catch (e){
console.log(e)
var sql = `INSERT IGNORE INTO pedodb (id, flag) VALUES ('${msg.author.id}', 'M')`;
con.query(sql, function (err) {
if (err) throw err;
console.log("Database Updated: Minor Added")
});
}
}
Is there any way to make this more efficient and fix the error? This is a pretty big problem haha