我刚刚使用新的Discord.js机器人设置了PostgreSQL数据库。我不断收到一条错误消息,指出“错误:“用户的用户名”列不存在”。我什至对它进行了设置,以便如果没有行,则添加一个并创建一个。
代码如下:
module.exports = (bot, message, args, con) => {
const selecttext = `SELECT * FROM hbucks WHERE id = ${message.author.id} AND guildid = ${message.guild.id}`;
con.query(`SELECT * FROM hbucks WHERE id = ${message.author.id} AND guildid = ${message.guild.id}`, (err, res) => { //Where id defines what row to use, this is stating that you are going to organize it by the id
if(err) throw(err.stack);
let sql;
let username = message.author.username
let authorid = message.author.id
const inserttext = `INSERT INTO users(id, username, guildid, hbucks) VALUES(${message.author.id}, ${message.author.username}, ${message.guild.id}, ${generateXp()})`;
const insertvalues = ['${message.author.id}', '${message.author.username', '${message.guild.id}', '${generateXp()}'];
if(!res) {
console.log("Works!!!");
con.query(`INSERT INTO users(id, username, guildid, hbucks) VALUES(${message.author.id}, "${message.author.username}", ${message.guild.id}, ${generateXp()}`);
} else {
let hBucks = res.hbucks;
hBucks = parseInt(hBucks);
const updatehbucks = `UPDATE hbucks SET hbucks = ${hBucks + generateXp()} WHERE id = ${authorid} AND guildid = ${message.guild.id}`;
const updateusername = `UPDATE hbucks SET username = "${message.author.username}" WHERE id = ${authorid} AND guildid = ${message.guild.id}`;
con.query(`UPDATE hbucks SET hbucks = ${hBucks + generateXp()} WHERE id = ${authorid} AND guildid = ${message.guild.id}`);
con.query(`UPDATE hbucks SET username = "${message.author.username}" WHERE id = ${authorid} AND guildid = ${message.guild.id}`);
}
}
)}