【问题标题】:Discord Bot not going online [duplicate]Discord Bot没有上线[重复]
【发布时间】:2021-11-11 23:21:28
【问题描述】:
require("dotenv").config();
const { Client, Intents } = require("discord.js");

const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});

client.on("ready", () => {
  console.log("bot is ready");
});

client.login(process.env.DISCORD_BOT_TOKEN).catch((e) => {
  console.log(e);
});

输出

HTTPError [ReferenceError]: AbortController is not defined
    at RequestHandler.execute (g:\goofy-translator\node_modules\discord.js\src\rest\RequestHandler.js:172:15)
    at RequestHandler.execute (g:\goofy-translator\node_modules\discord.js\src\rest\RequestHandler.js:176:19)
    at RequestHandler.push (g:\goofy-translator\node_modules\discord.js\src\rest\RequestHandler.js:50:25)
    at async WebSocketManager.connect (g:\goofy-translator\node_modules\discord.js\src\client\websocket\WebSocketManager.js:128:9)
    at async Client.login (g:\goofy-translator\node_modules\discord.js\src\client\Client.js:245:7) {
  code: 500,
  method: 'get',
  path: '/gateway/bot',
  requestData: { json: undefined, files: [] }
}

错误是由 client.login() 方法引起的。已经三次检查了机器人令牌,一切似乎都很好。问题也不在环境变量中,因为当我直接传递令牌时也不起作用。

[已解决] 问题是节点版本,discord.js 需要 v16 分钟

【问题讨论】:

标签: javascript node.js discord.js


【解决方案1】:

自 Discord.js 版本 13 起,该库要求您使用更新的 Node.js 版本。根据docs,需要使用Node.js v16.6.0或更高版本。

有关如何更改节点版本或使用多个节点版本的详细信息,请参阅NVM for WindowsNVM for Linux,具体取决于您的操作系统。

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 2021-12-26
    • 2021-10-31
    • 2020-10-18
    • 2020-04-28
    • 2021-11-18
    • 2021-01-20
    • 2020-09-12
    • 2021-12-16
    相关资源
    最近更新 更多