I am creating a bot that contains a "!warn" command that allows to report a user. the reports are recorded in a database. At the end of the code I have a query that checks if there are users that year + or = to 10 warnings. The problem is that if a user is warned, it's as if it's not updated in the database until the end of the code.
case ("!warn"):
if(message.member.roles.cache.has('------------------')){
if(message.mentions.members.first() != undefined){
var select = "SELECT warns FROM DiscordUsers WHERE username='" + message.mentions.members.first().user.username + "'";
con.query(select, function (err, result, fields) {
var temp = parseInt(result[0].warns);
temp++;
var update = "UPDATE DiscordUsers SET warns = '" + temp + "' WHERE username='" + message.mentions.members.first().user.username + "'";
con.query(update, function (err, result) {
});
});
message.channel.send("succesfully warned");
}else{
message.channel.send("Uncomplete command");
}
}else{
message.channel.send("You have been automatically reported for incorrect use of a command.");
autoWarn(message);
verfyBan(bot);
}
break;
Here at the execution of the code the warnings of the user are updated by 9 10, for ex. Then at the end of the whole program I execute this piece of code:
con.query(select, function (err, result, fields) {
for (var i = 0; i < result.length; i++) {
if(result[i].warns >= 10){
let member = message.guild.members.cache.get(result[i].id_user);
member.roles.remove("------------------");
member.roles.remove("------------------");
member.roles.remove("------------------");
member.roles.remove("------------------");
}
}
});
But at this point the wanr returned from the db are still worth nine, and as if at the end of all the program did all the queries in one go. can anyone help me to make sure that if one gets to 10 war is actually disabled by removing all the roles?