Slash commands not working

So I have registered my / commands and when I type them, I have a console log to show that it has received the interaction and which one was executed, but it doesn't actually execute the commands.
This is my interactionCreate handler
const { Events } = require('discord.js');

module.exports = {
  name: Events.InteractionCreate,
  async execute(interaction) {
    console.log(`Interaction received: ${interaction.commandName}`);
    if (interaction.isChatInputCommand()) return;

    const command = interaction.client.commands.get(interaction.commandName);

    if (!command) {
      console.error(`No command found for ${interaction.commandName}`);
      return;
    }

    try {
      await command.execute(interaction);
    } catch (e) {
      console.error(`Error executing command ${interaction.commandName}: ${e}`);
      if (interaction.replied || interaction.deferred) {
        await interaction.followUp({ content: 'An error occurred while executing the command.', ephmeral: true });
      } else {
        await interaction.reply({ content: 'An error occurred while executing the command.', ephmeral: true });
      }
    }
  },
}

and this is my event handler
const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
  const filePath = path.join(eventsPath, file);
  const event = require(filePath);
  if (event.once) {
    client.once(event.name, (...args) => event.execute(...args));
  } else {
    client.on(event.name, async (...args) => await event.execute(...args));
  }
}
Was this page helpful?