【发布时间】: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... 并且什么都不做 - 我想你可能错过了类继承的要点
标签: javascript node.js discord discord.js