为什么当我用节点启动我的机器人时 discord.js 模块出现错误?

Why is there an error with discord.js module when i start my bot with node?

最近我的机器人 discord 出现了一个奇怪的错误。 discord.js 每当我 运行 我的机器人时似乎都会崩溃 :

[nodemon] 2.0.12
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node ./src/index.js`    
C:\Users\myname\Documents\Loisir\Dev\Discord_Bots\Aura-discord\bot\node_modules\discord.js\src\rest\RESTManager.js:32
    const token = this.client.token ?? this.client.accessToken;
                                     ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:1070:16)
    at Module._compile (internal/modules/cjs/loader.js:1120:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\Users\hugo\Documents\Loisir\Dev\Discord_Bots\Aura-discord\bot\node_modules\discord.js\src\client\BaseClient.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
[nodemon] app crashed - waiting for file changes before starting...

这在我更新我的 discord.js 和节点模块后开始发生,所以我认为这不是真正的代码问题,更多的只是我搞砸了更新。我是 discord.js 和节点的新手,所以这很可能真的很简单。

我试图用 node 而不是 nodemon 启动它,但我得到了这个:

C:\Users\hugo\Documents\Loisir\Dev\Discord_Bots\Aura-discord\bot\node_modules\discord.js\src\client\Client.js:544
      throw new TypeError('CLIENT_MISSING_INTENTS');
      ^

TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
    at Client._validateOptions (C:\Users\hugo\Documents\Loisir\Dev\Discord_Bots\Aura-discord\bot\node_modules\discord.js\src\client\Client.js:544:13)
    at new Client (C:\Users\hugo\Documents\Loisir\Dev\Discord_Bots\Aura-discord\bot\node_modules\discord.js\src\client\Client.js:73:10)
    at Object.<anonymous> (C:\Users\hugo\Documents\Loisir\Dev\Discord_Bots\Aura-discord\bot\src\index.js:5:16)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47 {
  [Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}

我有点迷茫(我是说很多)所有这些,我在互联网上真的找不到任何东西。

这是我的依赖项,如果有帮助的话:

{
  "name": "Aura-discord",
  "version": "0.0.1",
  "description": "Aura is a bot specialized in the creation and management of tournaments on discord.",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon ./src/index.js",
    "start": "node ./src/index.js",
    "build": ""
  },
  "keywords": [],
  "author": "myName",
  "mail": "hberferf@auradiscord.bot",
  "website": "http://aura-discord.bot",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^13.0.1",
    "mongoose": "^5.13.5",
    "node": "^16.6.1"
  },
  "devDependencies": {
    "nodemon": "^2.0.12"
  }
}

感谢您花时间阅读本文,如有拼写错误,敬请谅解。

如果您检查 Discord.js 的 upgrade guide, it mentions that it requires Node.js v16.6 or higher. According to Node.green,无效合并运算符仅在 Node.js v14.5.0 或更高版本中受支持,所以我认为您的错误是没有正确升级 Node.js。我确实注意到你的依赖项中有 node?它应该在引擎中,不会 upgrade Node.js,它只会在您使用错误的版本时警告您。正确安装 Node.js v16.6 或更高版本。

可以 在技术上使用 node NPM 模块来 运行 不同版本的 Node.js 但这看起来很奇怪。不过,它确实解决了无效合并运算符的问题。升级指南中也解释了第二个错误的原因,准确地说是this section