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')
}
});
我希望有人能提供帮助,我和我的朋友们一直在努力解决错误,但我们无法解决 我会将错误发送给任何可以帮助的人, 我和我的朋友在命令中包含命令,我已经执行了命令,但是我知道他们给了我们错误。
答案 0 :(得分:0)
只需在声明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')
}
});