【问题标题】:agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });代理 ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
【发布时间】:2021-11-26 22:40:57
【问题描述】:

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

这是我的bot.js

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

这是我的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"
  }
}

所以当我运行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)

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

【问题讨论】:

标签: javascript node.js discord discord.js node-modules


【解决方案1】:

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

【讨论】:

  • 非常感谢,问题解决了:)))
【解决方案2】:

您需要将 Node 更新到 16.6.0 或更高版本才能正常工作并修改您的

第 2 行和第 3 行

代码:

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

防止

[符号(代码)]:'CLIENT_MISSING_INTENTS' 错误

从文档中了解更多信息 https://discord.js.org/#/docs/main/stable/general/welcome

【讨论】:

    猜你喜欢
    • 2021-12-04
    • 2022-01-25
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多