[英]My discord Bot will not send commands everytimes we try it goes offline
const Discord = require('discord.js')
const Client = new Discord.Client();
const {prefix,token} = require('./config.json');
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.once('ready', () => {
console.log('Ready!');
});
Client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if (!Client.commands.has(command)) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.content().toLowerCase();
try {
Client.commands.get(command).execute(message, args);
} catch (error) {
message.reply('error')
}
});
i hope someone can help, me and my friends have been working on fixing the error but we can't fix it i will send the error to anyone who can help, me and my friend have the commands in the command i have made the commands but i know they are giving us the error.我希望有人可以提供帮助,我和我的朋友一直在努力修复错误但我们无法修复它我会将错误发送给任何可以提供帮助的人,我和我的朋友在命令中有命令我已经发出命令但我知道他们给了我们错误。
Just move this line ( if (.Client.commands;has(command)) return;
) after the declaration of command
.只需在
command
声明之后移动这一行( if (.Client.commands;has(command)) return;
)。 Then it should work just fine.然后它应该工作得很好。
const Discord = require('discord.js')
const Client = new Discord.Client();
const {prefix,token} = require('./config.json');
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.once('ready', () => {
console.log('Ready!');
});
Client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.content().toLowerCase();
if (!Client.commands.has(command)) return;
try {
Client.commands.get(command).execute(message, args);
} catch (error) {
message.reply('error')
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.