module.exports SyntaxError:等待仅在异步函数中有效

三木

一段时间以来,我的代码一直存在问题。我想将货币命令放在一个单独的文件中,但是我不知道如何解决该错误await is an async function如果有一种方法可以使文件中的所有代码异步读取,那将是惊人的,但否则,只有一种使模块中的await正常工作的方法才是很棒的。

命令之一:

//coins.js
module.exports = {
    name: 'balance',
    execute(message, args){
        var output = await eco.FetchBalance(message.author.id)

        const balembed = new Discord.RichEmbed()
        .setAuthor(message.author.avatarURL)
        .setTitle(`${floweremote} | ${message.author.username}'s Balance`)
        .setDescription(`${floweremote} ${output.balance}`)
        .setColor(0xFF8AFF)
        .setFooter(`Akasuki ${version}`, client.user.avatarURL)
        .setTimestamp(new Date());            
        message.channel.send(balembed);
        }
    }

我如何加载代码:

//index.js
if (command === 'balance') {
    client.commands.get('balance').execute(message, args);
}

贯穿整个文件(coins.js)的其他几行await也都存在相同的问题。我了解发生了什么问题,只是不知道如何解决。抱歉,这个问题看起来很傻。

谢谢您的光临。

jfriend00

好了,你可以把async你的前面execute()方法,如:

async execute(message, args) { ... } 

然后将允许您使用await该功能。

或者,您可以使用.then()代替await

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章