【问题标题】:Valid intents must be provided for the Client [duplicate]必须为客户提供有效的意图[重复]
【发布时间】:2021-12-30 09:25:50
【问题描述】:

我正在编写一个不和谐的机器人,但我无法摆脱这个错误。我已经看到了一些对其他人有用但对我不起作用的解决方案...我不断收到此错误:

throw new TypeError('CLIENT_MISSING_INTENTS');
  ^ TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (C:\Users\User\Desktop\discordBot\node_modules\discord.js\src\client\Client.js:548:13)
at new Client (C:\Users\User\Desktop\discordBot\node_modules\discord.js\src\client\Client.js:76:10)
at Object.<anonymous> (C:\Users\User\Desktop\discordBot\main.js:3: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:81:12)
at node:internal/main/run_main_module:17:47 {   [Symbol(code)]: 'CLIENT_MISSING_INTENTS' }

这是我的 main.js 代码:

const Discord = require('discord.js');
 
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
 
const prefix = '-';
 
const fs = require('fs');
 
client.commands = new Discord.Collection();
 
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
 
    client.commands.set(command.name, command);
}
 
 
client.on('ready', () => {
    console.log('bot is online!');
});
 
 
client.on('message', message => {
 
    if (!message.content.startsWith(prefix) || message.author.bot) return;
 
    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
    if (command === 'reactionrole') {
        client.commands.get('reactionrole').execute(message, args, Discord, client);
    } 
  
});
 
client.login('TOKEN');

有人知道我能做些什么吗?

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

您在创建新客户端时缺少意图字段。替换

const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});

const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ], intents: ["GUILDS", /* Other intents... */]});

【讨论】:

    猜你喜欢
    • 2021-10-12
    • 2021-10-14
    • 2021-10-17
    • 2021-12-02
    • 2022-06-19
    • 2016-03-28
    • 2017-07-18
    • 2020-08-10
    • 2021-05-23
    相关资源
    最近更新 更多