首页 > 解决方案 > 运行 discord.js bot 时出现此错误

问题描述

当我使用 discord.js 运行不和谐机器人时

[my\path\discord.js\bot]
> node bot.js
C:\Users\username\node_modules\discord.js\src\rest\APIRequest.js:33
    agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
          ^^^

SyntaxError: Unexpected token '??='
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (C:\Users\username\node_modules\discord.js\src\rest\RESTManager.js:4:20)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

[my\path\discord.js\bot]

>

我认为这是休息客户端语法错误我该如何解决?

标签: restdiscord.js

解决方案


假设这是 Discord.js v13,您需要使用 Node 16.6.0+,如文档中所述。您收到的错误很可能是由于您的 Node 版本低于该版本,因为??=如果您使用正确版本的 node.js 应该可以工作。

逻辑无效赋值( ??=) 对 Node 来说相对较新(根据 node.green 为15.14.0),您需要将其更新到至少 16.6.0 才能使 Discord.js v13 充分发挥作用。


推荐阅读