【发布时间】:2021-07-13 16:43:47
【问题描述】:
const db = require('quick.db');
module.exports = {
name: 'bal',
description: "Check your coin balance.",
execute(message, args) {
let profile = db.get(`${message.author.id}`)
if (!profile.coins) return message.lineReply('You currently have 0 coins.')
message.lineReply(`You currently have ${profile.coins} coins.`);
}
}
这是我的 discord.js 机器人的 balance 命令的命令文件。 该脚本在控制台中输出:
TypeError: Cannot read property 'coins' of null
这里是关于数据库的更多信息:https://quickdb.js.org/
【问题讨论】:
-
看起来 db.get() 可能是一个 Promise,可能需要等待或用 .then 链接
-
@Hyetigran - 不,如果是这种情况,
profile.coins将是undefined,而不是错误。错误说profile是null。 -
错误告诉你
profile是null。所以你必须找出为什么db.get(`${message.author_id}`)会返回null。 (我对此感到惊讶,因为像 Hyetigran 一样,我本来希望它返回一个承诺,但也许它是一个老式的基于回调的 API。)(旁注:db.get(`${message.author_id}`)是一种复杂的编写方式 @987654333 @. :-) ) -
请添加有关您使用的数据库的详细信息,只有这样我们才能完全诊断您的问题。
-
我们能否也看到您的数据库设置代码。没有它,我们就不能再进一步了。
标签: javascript node.js discord.js