所以,我刚刚开始在Javascript中编写机器人,这是我以前从未使用过的东西。我正在遵循视频中看到的确切步骤,但是,当我在终端中运行node .
时,我得到一个错误:
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:UsersAcerDesktopDiscordBotsSEnode_modulesdiscord.jssrcclientClient.js:548:13)
at new Client (C:UsersAcerDesktopDiscordBotsSEnode_modulesdiscord.jssrcclientClient.js:76:10)
at Object.<anonymous> (C:UsersAcerDesktopDiscordBotsSEindex.js:2:13)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159: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:77:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
这是我的代码:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES] });
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = 'i aint showing you my token';
const PREFIX = '';
bot.on('ready', () => {
console.log('SEBot is online.')
})
bot.login(token)
我不明白问题是什么,一些帮助真的会解决的。谢谢。
首先,你已经用
初始化了你的客户端const client = new Client({ intents: [Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES] });
然后初始化另一个,现在没用了。你应该删除
const Discord = require('discord.js');
const bot = new Discord.Client();
您的客户端(具有有效意图)应该是您调用.on()
函数的客户端,因此将bot.on()
和bot.login()
切换为client.on
和client.login