簡體   English   中英

當我啟動我的機器人 discord 時出現錯誤,我找不到解決方法

[英]when i launch my bot discord i have an error and i can't find how to fix it

你好,我正在嘗試編寫我的第一個機器人,尤其是一個命令,讓它給出它的 ping 和 API 但是當我啟動機器人時,我遇到了這個錯誤,我不知道如何修復它

        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);
    }
}

(是的,我是法國人)

謝謝您的回答

正如錯誤所述,您在非異步 function 中使用await

為您的代碼編寫一個單獨的async function 並導出該 function:

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

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

檢查 discord 指南

有關異步/等待的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM