Discord.js (V12) |禁止命令



我正在制作一个不和谐的机器人,我想做一个禁止命令。当我尝试使用这个命令时,这个错误弹出在我的终端:TypeError: client.commands.get(...).execute is not a function at Client.<anonymous> (C:UsersLucasDesktopDiscord BOTindex.js:29:32)我做错了什么?我尝试了多种解决方案,我在StackOverflow或v12.discordjs上找到了。但是我的尝试都没有效果。谢谢你的帮助!

这是index.js文件:

const fs = require('fs');
const Discord = require('Discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
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, Discord);
}
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.shift().toLowerCase();

if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args, Discord);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
if (command.permissions) {
const authorPerms = message.channel.permissionsFor(message.author);
if (!authorPerms || !authorPerms.has(command.permissions)) {
return message.reply('You can not do this!');
}
}
});
client.login(token);

这是ban命令文件(ban.js):

const Discord = require("Discord.js");
module.exports = {
name: 'ban',
description: 'Banish someone',
permissions: 'ADMINISTRATOR',
usage: 'ban @user <reason>',

run: async (message, client, args) => {
if (!target) {
return message.channel.send(`${message.author.username} USAGE: ban @user reason`)
}
if(target.id === message.author.id) {
return message.channel.send(`${message.author.username}, You can't ban yourself. YOU FOOL!`)
}
if(!args[1]) {
return message.channel.send(`${message.author.username}, Please give a reason to ban that member`)
}
let embed = new Discord.MessageEmbed()
.setTitle('Action: BAN')
.setDescription(`Banned ${target} (${target.id})`)
.setColor("0ff")
.setFooter(`Banned by ${message.author.tag}`);
message.channel.send(embed)
target.ban(args[1])
}
}

在index.js文件中,使用client.commands.get(command).execute(message, args, Discord);

运行命令然而,在你的ban.js文件中,你有一个run关键字not execute,试着用它来代替

execute: async (message, client, args) => {

最新更新