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

Javascript 数据未定义,而我已经定义了它?,javascript,undefined,discord.js,Javascript,Undefined,Discord.js,好吧,我用的是不和谐经济npm 我已经定义了平衡,但当我尝试输出时,什么也没发生。我试图添加一个“支持aka工作”的东西,但仍然没有什么,以下是我迄今为止的代码 if (msg.content === prefix + "bal") { const output = eco.FetchBalance(msg.author.id) msg.channel.send(`${output.balance}`) if (msg.content === prefix + &q

好吧,我用的是不和谐经济npm 我已经定义了平衡,但当我尝试输出时,什么也没发生。我试图添加一个“支持aka工作”的东西,但仍然没有什么,以下是我迄今为止的代码

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
是一个承诺,它的字段是
userid
balance
。 您必须先等待承诺,以便实际获得返回的数据,如下所示:

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、 你不需要声明什么是未定义的?用户的余额,因为它获取余额然后输出,但它输出为未定义的余额,我已经完成了这个
const balance=0