I've been grappling over the past few days to successfully implement an SQL UPDATE event in discord.js using the mysql npm package. I have meticulously checked all login details, table names, and column names, but still can't get it to work as intended. The goal is to increment an integer each time a message is sent in a Discord text channel.
Despite trying various approaches for the UPDATE event, none seem to be yielding the desired results.
Take a look at these snapshot logs: - (Before/After the event trigger) - (discord.js console output when a message is sent)
bot.on("message", message => {
if (message.channel.type === 'dm') return;
if (message.author.bot) return;
if (message.content.startsWith(".")) return;
connection.query(`SELECT * FROM logs WHERE id = '${message.author.id}'`, function (err, resultLogs) {
if(err) throw err;
let sql;
if(resultLogs[0]) {
console.log(resultLogs[0].msgcount);
let newMessageCount = resultLogs[0].msgcount++;
sql = `UPDATE logs SET msgcount = ${newMessageCount} WHERE id=${message.author.id}`;
connection.query(sql, console.log);
}
});
});
The expected behavior is that the integer should increment by one every time a message is sent.