gpt4 book ai didi

javascript - 类型错误 : Cannot read property 'exp' of undefined

转载 作者:行者123 更新时间:2023-11-30 11:33:19 25 4
gpt4 key购买 nike

我在我的 javascript 代码中使用 sqlite 作为数据库,无论我尝试什么,它总是在那里保留这个错误:

sql.get(`SELECT * FROM users WHERE userId ="${member.user.id}"`).then(row => {
if (!row) sql.run("INSERT INTO users (userId, level, exp) VALUES (?, ?, ?)", [member.user.id, 1, 0]);
var profile = new Discord.RichEmbed()
.setColor(0x0000FF)
.setTitle(member.user.username + "'s profile")
.setThumbnail(member.user.avatarURL)
.setDescription("Status: " + member.user.presence.status)
.addField("Stats","**Level** " + row.level+"\n"+row.exp+"/"+row.level*10)
msg.reply("here is "+member.user.username+"'s profile:",{embed:profile});
})

如果您没有理解其中的一些内容,例如“msg.reply”,那是因为这些是我的 discord 机器人的命令。

最佳答案

看起来您的对象行未定义。

将所有代码包裹在 else 花括号中:

sql.get(`SELECT * FROM users WHERE userId ="${member.user.id}"`).then(row => {
if (!row)
sql.run("INSERT INTO users (userId, level, exp) VALUES (?, ?, ?)", [member.user.id, 1, 0]);
else {
var profile = new Discord.RichEmbed()
.setColor(0x0000FF)
.setTitle(member.user.username + "'s profile")
.setThumbnail(member.user.avatarURL)
.setDescription("Status: " + member.user.presence.status)
.addField("Stats","**Level** " + row.level+"\n"+row.exp+"/"+row.level*10)
msg.reply("here is "+member.user.username+"'s profile:",{embed:profile});
}
})

关于javascript - 类型错误 : Cannot read property 'exp' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45456150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com