Estoy creando un bot de discordia y quiero hacer un comando de prohibición. Cuando intento usar el comando, aparece este error en mi terminal: TypeError: client.commands.get(...).execute is not a function at Client.<anonymous> (C:\Users\Lucas\Desktop\Discord BOT\index.js:29:32) ¿Qué hice mal? Probé varias soluciones que encontré en StackOverflow o v12.discordjs.guide, pero nada de lo que probé funcionó. ¡Gracias por ayudar!
Este es el archivo 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);Este es el archivo de comando de prohibición (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]) } }En su archivo index.js, ejecuta sus comandos usando client.commands.get(command).execute(message, args, Discord);
sin embargo, en su archivo ban.js, tiene una palabra clave de ejecución que no se ejecuta, intente usar eso en su lugar
execute: async (message, client, args) => {