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 });
}
}
},
}
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 });
}
}
},
}