我有以下错误
UnhandledPromiseRejectionWarning: Error: SQLITE_ERROR: table scores has no column named points
有人知道修复吗?
我也使用discord.js命令,所以我的用户在run ...
中定义代码:
run(msg, {user, reason}) {
msg.delete()
if(!user) {msg.say(`**Cannot find user! Make sure it's a valid member of this server!**`)
} else {
msg.say(`**${user.tag} has been warned for ${reason}!**`)
sqlite.get(`SELECT * FROM scores WHERE userId = "${user.id}"`).then(row =>{
if (!row) {
sqlite.run("INSERT INTO scores (userId, points) VALUES (?,?)", [user.id, 1])
} else {
sqlite.run(`UPDATE scores SET points = ${row.points + 1} WHERE userId = ${user.id}`)
}
}).catch(()=>{
sqlite.run(`CREATE TABLE OF NOT EXISTS scores (userId TEXT, points INTEGER)`).then(()=> {
sqlite.run(`INSERT INTO scores (userId, points) VALUES (?, ?)`, [user.id, 1])
})
})
}
答案 0 :(得分:1)
你需要将承诺链接起来以便那样捕捉它们。
sqlite.get(`SELECT * FROM scores WHERE userId = "${user.id}"`).then(row =>{
if (!row) {
return sqlite.run("INSERT INTO scores (userId, points) VALUES (?,?)", [user.id, 1])
} else {
return sqlite.run(`UPDATE scores SET points = ${row.points + 1} WHERE userId = ${user.id}`)
}
}).catch(()=>{
return sqlite.run(`CREATE TABLE OF NOT EXISTS scores (userId TEXT, points INTEGER)`).then(()=> {
return sqlite.run(`INSERT INTO scores (userId, points) VALUES (?, ?)`, [user.id, 1])
}).catch((err) => {
console.error(err);
});