代理 ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });

Riy*_*Pal 3 javascript node.js node-modules discord discord.js

所以我正在学习如何使用discord.js 在discord 上制作机器人

这是我的bot.js

require("dotenv").config();
const { Client } = require('discord.js');
const client = new Client();
client.login(process.env.DISCORD_TOKEN_KEY);
Run Code Online (Sandbox Code Playgroud)

这是我的package.json文件:

{
  "name": "aibot",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node ./src/bot.js",
    "dev": "nodemon ./src/bot.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^13.2.0",
    "dotenv": "^10.0.0"
  }
}
Run Code Online (Sandbox Code Playgroud)

所以当我运行时node ./src/bot.js 我收到此错误:

PS E:\RIYA\AIBOT> node -v
v14.18.0

PS E:\RIYA\AIBOT> node ./src/bot.js
E:\RIYA\AIBOT\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> (E:\RIYA\AIBOT\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)
Run Code Online (Sandbox Code Playgroud)

我该怎么办?我对 NodeJs 不太了解,也不知道如何解决这个问题。

iam*_*eel 6

您必须按照文档将 node.js 更新到 v16.6 或更高版本(向下滚动到“安装”)。