38 lines
999 B
TypeScript
38 lines
999 B
TypeScript
import { Events, Interaction } from "discord.js";
|
|
import { BotClient } from "../types/botClient.js";
|
|
import logger from "../utils/logger.js";
|
|
|
|
export default {
|
|
name: Events.InteractionCreate,
|
|
async execute(interaction: Interaction, client?: BotClient) {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
if (!client) {
|
|
logger.error("Client not provided to interaction handler");
|
|
return;
|
|
}
|
|
|
|
const command = client.commands.get(interaction.commandName);
|
|
|
|
if (!command) {
|
|
await interaction.reply({
|
|
content: "Command not found!",
|
|
ephemeral: true,
|
|
});
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await command.execute(interaction, client);
|
|
} catch (error) {
|
|
logger.error(`Error executing command ${interaction.commandName}:`, error);
|
|
if (interaction.isRepliable()) {
|
|
await interaction.reply({
|
|
content: "There was an error while executing this command!",
|
|
ephemeral: true,
|
|
});
|
|
}
|
|
}
|
|
},
|
|
};
|