crv2/discord/events/InteractionCreate.ts

27 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-03-19 17:41:20 -04:00
import DiscordEvent from "../../util/DiscordEvent";
import { DiscordInteractionCommands } from "../../index";
2024-03-22 00:18:45 -04:00
import { Client, Interaction } from "discord.js";
2024-03-19 17:41:20 -04:00
export default class InteractionCreate extends DiscordEvent {
constructor(client: Client) {
super("interactionCreate", client);
}
public async execute(interaction: Interaction): Promise<void> {
if (!interaction.isChatInputCommand()) return;
const command = DiscordInteractionCommands.get(interaction.commandName);
if (!command) return console.error(`No command matching ${interaction.commandName} was found.`);
try {
await command.execute(interaction);
2024-10-24 20:40:14 -04:00
console.info(`[Info - Discord] Command '${interaction.commandName}' executed by '${interaction.user.username}'`);
2024-03-19 17:41:20 -04:00
} catch (error) {
2024-10-24 20:40:14 -04:00
console.error(`Error executing command '${interaction.commandName}': by '${interaction.user.username}'\n${error}`);
2024-03-19 17:41:20 -04:00
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
}
}