#Slash commands aren't being responded to

1 messages · Page 1 of 1 (latest)

spice wharf
still wave
#

your interactionCreate callback shouldn't take (client, interaction, args), pretty sure the event only passes an interaction

violet muskBOT
spice wharf
#

same thing

still wave
#

could you log something right at the top of the interactionCreate callback then
and also get rid of .catch(() => {}); 'cause that could be preventing you from seeing a nice error in the console

#

the log being to ensure it's even getting to where you defer

spice wharf
#

okay

spice wharf
#

.

#

mb for delay, laptop died 😂

violet muskBOT
#

<:_:874569322742308864> Client#ws
The WebSocket manager of the client

spice wharf
#

oops

#
const { Client, Interaction } = require('discord.js');

module.exports = {
    name: 'interactionCreate', // Event name
    once: true, // client.once() or client.on()
    /**
     * @param {Client} client
     * @param {Interaction} interaction
    */
    exec: async (client, interaction) => {
        if (interaction.isCommand()) {
            await interaction.deferReply({ ephemeral: false }).catch(() => {});
    
            const cmd = client.slash.get(interaction.commandName);
            if (!cmd) return interaction.followUp({ content: "An error has occured - Unknown command" });
    
            const args = [];

            for (let option of interaction.options.data) {
                if (option.type === "SUB_COMMAND") {
                    if (option.name) args.push(option.name);
                    option.options?.forEach((x) => {
                        if (x.value) args.push(x.value);
                    });
                } else if (option.value) args.push(option.value);
            }
            interaction.member = interaction.guild.members.cache.get(interaction.user.id);
    
            cmd.exec(client, interaction, args);
        }
    
        // Context Menu Handling
        if (interaction.isContextMenu()) {
            await interaction.deferReply({ ephemeral: false });
            const command = client.slash.get(interaction.commandName);
            if (command) command.exec(client, interaction);
        }
    }
};
rigid bane
#

client.once() means that the event will only be emitted once

spice wharf
#

okay

spice wharf
#
        if (interaction.isCommand()) {
                        ^

TypeError: Cannot read properties of undefined (reading 'isCommand')```
#

still getting that error

rigid bane
#

show me your event handler code

spice wharf
rigid bane
#

ok wait

spice wharf
#

k

rigid bane
# spice wharf k

remove the client from exec: async (client, interaction)

if you want to access client, you can do so via interaction.client

spice wharf
#

ok

#

nvm i got it to work i just had to mess around with some global variables

#

thanks @rigid bane for helping :D