好吧,我正在编写一个Discord机器人。现在,我需要检查数据库中某个用户的警告或禁令数量。问题是,要检查它的函数返回0
(执行查询后,它不会更新cant
的值)
我一直在寻找其他主题的答案,但我发现了一些东西,但这根本不起作用...
function checkQuery(user, type) {
var cant = 0;
var sql = `SELECT count(*) AS amount FROM moderation WHERE type = '${type}' AND user = '${user}'`;
con.connect(() => {
console.log("Connected!");
con.query(sql, (err, result) => {
if (err) throw err;
cant = result[0].amount;
console.log(cant); // this shows the real value!! but still returning 0
});
});
return cant;
}