Polarcraft/discordbot/events/interactionCreate.js

26 lines
813 B
JavaScript
Raw Normal View History

2023-08-02 14:16:30 +02:00
const { Events } = require('discord.js');
2023-08-17 10:23:15 +02:00
const { simpleEmbed } = require('../functions/embeds.js');
2023-08-02 14:16:30 +02:00
module.exports = {
2023-08-03 12:06:31 +02:00
name: Events.InteractionCreate,
async execute(interaction) {
2023-08-11 11:14:59 +02:00
if (interaction.isChatInputCommand() || interaction.isUserContextMenuCommand()) {
const command = interaction.client.commands.get(interaction.commandName);
2023-08-02 14:16:30 +02:00
2023-08-11 11:14:59 +02:00
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
2023-08-02 14:16:30 +02:00
2023-08-11 11:14:59 +02:00
try {
await command.execute(interaction);
} catch (error) {
2023-08-17 11:43:22 +02:00
await interaction.reply({ embeds: [simpleEmbed('There was an error while executing the command')], ephemeral: true });
2023-08-11 11:14:59 +02:00
console.error(`Error executing ${interaction.commandName}`);
console.error(error);
}
2023-08-03 12:06:31 +02:00
}
2023-08-02 14:16:30 +02:00
2023-08-03 12:06:31 +02:00
},
2023-08-02 14:16:30 +02:00
};