如何解决我不和谐的Bot每次尝试离线时都不会发送命令
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')
}
});
我希望有人能提供帮助,我和我的朋友们一直在努力解决错误,但我们无法解决 我会将错误发送给任何可以帮助的人, 我和我的朋友在命令中包含命令,我已经执行了命令,但是我知道他们给了我们错误。
解决方法
只需在声明if (!Client.commands.has(command)) return;
之后移动这一行(command
)。然后就可以了。
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')
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。