crv2/discord/events/InteractionCreate.ts

37 lines
1.3 KiB
TypeScript
Raw Permalink 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 {
2024-10-25 16:57:33 -04:00
constructor(client: Client) {
super("interactionCreate", client);
}
2024-03-19 17:41:20 -04:00
2024-10-25 16:57:33 -04:00
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);
console.info(
`[Info - Discord] Command '${interaction.commandName}' executed by '${interaction.user.username}'`
);
} catch (error) {
console.error(
`Error executing command '${interaction.commandName}': by '${interaction.user.username}'\n${error}`
);
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,
});
}
2024-03-19 17:41:20 -04:00
}
2024-10-25 16:57:33 -04:00
}
2024-03-19 17:41:20 -04:00
}