Javascript Discord.js机器人//主文件中有多个机器人问题
我试图将多个机器人程序放入一个文件中,但我一直都遇到此错误: ReferenceError:无法在初始化之前访问“fs” 我不知道该怎么办了。如果你有任何线索,hmu:) 代码如下:Javascript Discord.js机器人//主文件中有多个机器人问题,javascript,command,discord.js,bots,Javascript,Command,Discord.js,Bots,我试图将多个机器人程序放入一个文件中,但我一直都遇到此错误: ReferenceError:无法在初始化之前访问“fs” 我不知道该怎么办了。如果你有任何线索,hmu:) 代码如下: const clients = new Discord.Collection([ [ "peter", // key { // value name: "peter", client: new Discord.C
const clients = new Discord.Collection([
[
"peter", // key
{ // value
name: "peter",
client: new Discord.Client({
presence: {
status: "online",
activity: {
type: "WATCHING",
name: "something on tv",
},
},
}),
commandsPath: "./firstCommands",
prefix: "-",
token: "token1",
},
],
// second key
[
"ayse", // key
{ // value
name: "ayse",
client: new Discord.Client({
presence: {
status: "online",
activity: {
type: "WATCHING",
name: "something on tv",
},
},
}),
commandsPath: "./firstCommands",
prefix: "-",
token: "token2",
},
],
]);
clients.forEach(({ client, token, commandPath, name }) => {
const commandFiles = fs.readdirSync(commandPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles){
const command = require(`${commandPath}/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log(`${name} is ready`)
});
client.login(token);
});
和命令处理程序:
clients.forEach((data) => {
data.client.on('message', (message) => {
if (!message.content.startsWith(data.prefix) || message.author.bot) return;
const args = message.content.slice(data.prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
try {
data.client.commands.get(command).execute(message, args);
} catch {
message.channel.send("I do not know that command.");
};
});
});
因此,它们都应该在主文件上运行,然后在另一个文件夹中导出命令。。
谢谢