如何解决Discord.js机器人程序//主文件问题中包含多个机器人程序
我试图将多个机器人合并到一个文件中,但是我总是遇到此错误: ReferenceError:初始化前无法访问“ fs”
我不知道该怎么办了。如果您有任何线索,hmu :) 这是代码:
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",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.");
};
});
});
因此,它们都应在主文件上运行,然后将命令导出到另一个文件夹中。 谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。