我如何修复 CLIENT_MISSING_INTENTS 错误-Discord.js [重复]
Posted
技术标签:
【中文标题】我如何修复 CLIENT_MISSING_INTENTS 错误-Discord.js [重复]【英文标题】:How do i fix CLIENT_MISSING_INTENTS error - Discord.js [duplicate] 【发布时间】:2021-10-15 10:19:27 【问题描述】:我正在开发一个不和谐的机器人,但在开始之前我遇到了这样的错误。我需要你的帮助。谢谢!
这是我的代码:
在 index.js 中
const EconomyClient = require('./structures/Client');
new EconomyClient().start(require('./config').token, './commands');
如果你需要这个代码部分,这里是 client.js
client.js
const Client, Intents, Collection = require('discord.js');
const client = new Client( intents: [Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES] );
class EconomyClient extends Client
constructor()
super();
this.discord = require('discord.js');
this.fs = require('fs');
this.path = require('path');
this.ms = require('ms');
this.mongoose = require('mongoose');
this.commands = new Collection();
this.timeouts = new Collection();
this.config =
prefix: 'h!',
commandHandler(path)
this.fs.readdirSync(this.path.normalize(path)).map((f) =>
const File = require(this.path.join(__dirname, '..', path, f));
this.commands.set(File.name, File);
);
;
start(token, path)
this.commandHandler(path);
this.login(token);
this.mongoose.connect('mongodb+srv://dbUser:@cluster0.awhb3.mongodb.net/Data?retryWrites=true&w=majority',
useNewUrlParser: true,
useUnifiedTopology: true
);
this.mongoose.connection.on('connected', () => console.log("DB connected"));
;
module.exports = EconomyClient
还有我的问题:
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at EconomyClient._validateOptions (C:\Users\oktay\Desktop\heise\node_modules\discord.js\src\client\Client.js:544:13)
at new Client (C:\Users\oktay\Desktop\heise\node_modules\discord.js\src\client\Client.js:73:10)
at new EconomyClient (C:\Users\oktay\Desktop\heise\structures\Client.js:4:9)
at Object.<anonymous> (C:\Users\oktay\Desktop\heise\index.js:2:1)
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:79:12)
at node:internal/main/run_main_module:17:47
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
【问题讨论】:
你搜索堆栈溢出了吗? this 似乎是 4 天前才提出的同一个问题 @Bravo 我试过了,但我仍然有同样的问题。感谢您的建议 哦,根本看不到你在哪里调用new Client
- 也许你做错了 - 你能显示更新的代码
我正在编辑问题(Client.js)
所以,你创建了 const client = new Client
... 并且什么都不做 - 我想你可能错过了类继承的要点
【参考方案1】:
我再解释一遍。
If you need your bot to receive messages (MESSAGE_CREATE - "messageCreate" in discord.js), you need the GUILD_MESSAGES intent. If you want your bot to post welcome messages for new members (GUILD_MEMBER_ADD - "guildMemberAdd" in discord.js), you need the GUILD_MEMBERS intent, and so on.
所以,提出有效的意图,它就会起作用。 您也可以将它们中的每一个都放在将来,您将永远不会再出现此错误。
【讨论】:
以上是关于我如何修复 CLIENT_MISSING_INTENTS 错误-Discord.js [重复]的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Objective-C 修复 UIViewController 中的页脚?