数据未定义,而我已经定义了它?

Data being undefined while I have already defined it?

好的,所以我正在使用不和谐经济 npm Discord-Economy Npm 我已经定义了平衡,但是当我尝试输出时没有任何反应。我试图添加一个“支持又名工作”的东西,但仍然没有,这是我到目前为止的代码

if (msg.content === prefix + "bal") {
 const output = eco.FetchBalance(msg.author.id)
 msg.channel.send(`${output.balance}`) 

 if (msg.content === prefix + "support") {
const output = eco.FetchBalance(msg.author.id)
msg.channel.send(`${output.balance}`)
}

查看文档,FetchBalance 是一个承诺,它的字段是 useridbalance。 你必须先等待承诺,这样你才能真正得到返回的数据,如下所示:

if (msg.content === prefix + "bal") {
 const output = await eco.FetchBalance(msg.author.id) // Adding await to fulfil the promise
 msg.channel.send(`${output.balance}`) 

 if (msg.content === prefix + "support") {
const output = await eco.FetchBalance(msg.author.id)
msg.channel.send(`${output.balance}`)
}

p.s。你不需要声明 const balance = 0