Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我启动bot discord时,我有一个错误,我可以';我不知道如何修理它_Javascript_Node.js_Discord_Discord.js - Fatal编程技术网

Javascript 当我启动bot discord时,我有一个错误,我可以';我不知道如何修理它

Javascript 当我启动bot discord时,我有一个错误,我可以';我不知道如何修理它,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,您好,我正在尝试编写我的第一个bot,特别是一个命令,让它发出ping和API的ping,但是当我启动bot时,我出现了这个错误,我不知道如何修复它 waiting = await message.channel.send("Je calcule le ping...").catch(console.error); ^^^^^ SyntaxError: await is only valid in async functi

您好,我正在尝试编写我的第一个bot,特别是一个命令,让它发出ping和API的ping,但是当我启动bot时,我出现了这个错误,我不知道如何修复它

        waiting = await message.channel.send("Je calcule le ping...").catch(console.error);
                  ^^^^^

SyntaxError: await is only valid in async function
目前的代码是:

const Discord = require ("discord.js");

module.exports = {
    name: "ping",
    execute(bot, message, args){
        message.delete().catch(console.error);

        waiting = await message.channel.send("Je calcule le ping...").catch(console.error);

        let embed = new Discord.MessageEmbed()
        .setAuthor("Latence du bot & de l'api discord.js", bot.user.avatarURL)
        .setColor("RANDOM")
        .setTitle("pong !")
        .addField("**CactusBot :**", "> `" + `${bot.ws.ping}` + "ms`", true)
        .addField("**API :**", "> `" + Math.round(bot.ping) + "ms`", true)
        .setTimestamp(message.createdAt)
        .setFooter("Nuptay | demandé par @" + message.author.tag, bot.user.avatarURL)
        waiting.edit(pingEmbed).catch(console.error);
        message.channel.send(embed);
    }
}
(是的,我是法国人)


感谢您的回答

,因为错误表明您正在非异步函数中使用
wait

为代码编写单独的
async
函数并导出该函数:

const execute = async (bot, message, args) => {
  // your code with await
}

module.exports = {
  name: "ping",
  execute,
}


感谢您的快速响应,现在我有了这个错误:`execute async(bot、message、args){^^^^^^^ SyntaxError:意外标记'async'`哦,我已根据此更新了我的答案。好的,谢谢,我后来有错误,但我设法更正了它们,您知道如何使其也给我API的ping,因为现在它告诉我“NaNms”NaN表示“不是数字”,尝试先记录你需要的信息,看看里面有什么。嗯,我怎么做?这回答了你的问题吗?