My unban and ban commands arent showing when i put the slash

29 Views Asked by At

I was trying to code a bot with Discord.JS V14 since i always coded with the v12 and i watched the documentation and a few tutorials and i watched two. One for the clear command and the other for the ban and unban command, the clear command is showing and its totally functional when i type "/" and clear but when i wanna put /ban or /unban it doesnt show anything, my console doesnt shows any error

here is my code, some things are in spansish cuz im spanish but i can translate them if anyone need.

index:

const Discord = require('discord.js');
const configuracion = require('./config.json')
const cliente = new Discord.Client({
    intents: [
Discord.GatewayIntentBits.Guilds
    ]
});


module.exports = cliente

cliente.on('interactionCreate', (interaction) => {
    if(interaction.type === Discord.InteractionType.ApplicationCommand){
        
        const cmd = cliente.slashCommands.get(interaction.commandName);
        if(!cmd) return interaction.reply(`Error`);
        interaction["member"] = interaction.guild.members.cache.get(interaction.user.id);
        cmd.run(cliente, interaction)

    }
})

cliente.on('ready', () => {
    console.log(` Sesión iniciada como ${cliente.user.username}`)
})

cliente.slashCommands = new Discord.Collection()

require('./handler')(cliente)

cliente.login(configuracion.token)

index/handler

const fs = require('fs');
const Discord = require('discord.js');

module.exports = async (client) => {
    const SlashArray = [];

    fs.readdir('./Comandos', (error, folder) => {
        if (error) {
            console.error('Error al leer el directorio:', error);
            return;
        }

        if (!folder || folder.length === 0) {
            console.error('No se encontraron carpetas en el directorio.');
            return;
        }

        folder.forEach(subfolder => {
            fs.readdir(`./Comandos/${subfolder}/`, (error, files) => {
                if (error) {
                    console.error('Error al leer archivos en la carpeta:', error);
                    return;
                }

                files.forEach(file => {
                    if (!file.endsWith('.js')) return;

                    const filePath = `../Comandos/${subfolder}/${file}`;
                    const command = require(filePath);

                    if (!command.name) return;

                    client.slashCommands.set(command.name, command);
                    SlashArray.push(command);
                });
            });
        });
    });

    client.on('ready', async () => {
        client.guilds.cache.forEach(guild => guild.commands.set(SlashArray));
    });
};

clear cmd

const fs = require('fs');
const Discord = require('discord.js');

module.exports = async (client) => {
    const SlashArray = [];

    fs.readdir('./Comandos', (error, folder) => {
        if (error) {
            console.error('Error al leer el directorio:', error);
            return;
        }

        if (!folder || folder.length === 0) {
            console.error('No se encontraron carpetas en el directorio.');
            return;
        }

        folder.forEach(subfolder => {
            fs.readdir(`./Comandos/${subfolder}/`, (error, files) => {
                if (error) {
                    console.error('Error al leer archivos en la carpeta:', error);
                    return;
                }

                files.forEach(file => {
                    if (!file.endsWith('.js')) return;

                    const filePath = `../Comandos/${subfolder}/${file}`;
                    const command = require(filePath);

                    if (!command.name) return;

                    client.slashCommands.set(command.name, command);
                    SlashArray.push(command);
                });
            });
        });
    });

    client.on('ready', async () => {
        client.guilds.cache.forEach(guild => guild.commands.set(SlashArray));
    });
};

ban cmd

const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits} = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName("ban")
        .setDescription("⛔ → Banea a un usuario determinado del servidor.")
        .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
        .addUserOption(option =>
            option.setName("usuario")
                .setDescription("Usuario que será baneado.")
                .setRequired(true)
        )
        .addStringOption(option =>
            option.setName("motivo")
                .setDescription("Un motivo para el baneo")
        ),

    async execute(interaction) {
        const usuario = interaction.options.getUser("usuario");
        const motivo = interaction.options.getString("motivo") || "No se proporcionó una razón.";

        const miembro = await interaction.guild.members.fetch(usuario.id);

        const errEmbed = new EmbedBuilder()
            .setTitle("️ Error 702")
            .setDescription(`No puedes tomar acciones sobre ${usuario.username} ya que tiene un rol superior al tuyo.`)
            .setColor("RED")
            .setTimestamp()
            .setFooter({ text: ` Comando enviado por ${interaction.user.tag} con id ${interaction.user.id}`, iconURL: interaction.user.displayAvatarURL() });

        if (miembro.roles.highest.position >= interaction.member.roles.highest.position)
            return interaction.reply({ embeds: [errEmbed] })

        await miembro.ban({ reason: motivo });

        const embedban = new EmbedBuilder()
            .setTitle("️ Acciones de baneo tomadas.")
            .setDescription(`ℹ️ El usuario ${usuario.tag} ha sido baneado\n **Motivo:** \`${motivo}\``)
            .setColor("GREEN")
            .setTimestamp()
            .setFooter({ text: ` Comando enviado por ${interaction.user.tag} con id ${interaction.user.id}`, iconURL: interaction.user.displayAvatarURL() });

        await interaction.reply({
            embeds: [embedban]
        });
    }
}

as you can see in the image it doesnt show any ban / unban commands only the ping one and clear / purge

I tried 2 diffferent ways of slash commands and thought it was gonna work but its not, i dont know what is, and ive been struggling for around 1 day, any suggestions?

0

There are 0 best solutions below