【发布时间】:2021-12-21 20:08:10
【问题描述】:
我尝试在 discord 上创建一个机器人,并且通过多个教程,我已按照所有说明进行操作,并且一开始似乎可以正常工作。但是,在所有教程中,我遇到了一个问题。在我的机器人的 index.js 文件中,当我打开 VSCode 终端并输入命令 node index.js(这应该让我的机器人上线时,我收到以下错误消息:
/Users/myname/Desktop/testbot/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 (/Users/myname/Desktop/testbot/node_modules/discord.js/src/client/Client.js:544:13)
at new Client (/Users/myname/Desktop/testbot/node_modules/discord.js/src/client/Client.js:73:10)
at Object.<anonymous> (/Users/myname/Desktop/testbot/index.js:2:13)
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:81:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
我安装了 node.js 16.13.0 和 discord.js。我的机器人是我服务器的成员,但它始终处于脱机状态。我能做些什么来解决它?
这是 index.js 的代码:
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '[not putting my token online]';
const PREFIX = '';
bot.on('ready', () => {
console.log('Online!');
});
bot.login(token);
【问题讨论】:
标签: javascript node.js visual-studio-code discord discord.js