artibot
Version:
Modern, fast and modular open-source Discord bot
40 lines • 1.47 kB
JavaScript
import { InteractionType } from "discord.js";
import log from "../logger.js";
import { SlashCommand } from "../modules.js";
export const name = "interactionCreate";
/** Slash command listener*/
export async function execute(interaction, artibot) {
const { localizer, modules } = artibot;
// Checks if the interaction is a command
if (interaction.type !== InteractionType.ApplicationCommand)
return;
const command = findCommand(interaction.commandName, modules);
// If the interaction is not a command in cache.
if (!command)
return;
// A try to executes the interaction.
try {
await command.execute(interaction, artibot);
}
catch (err) {
log("SlashHandler", err.message, "warn", true);
try {
await interaction.reply({
content: localizer._("An error occured while executing this command."),
ephemeral: true
});
}
catch (err) {
log("SlashHandler", localizer._("Additionally, an error occured when sending the error message to the user. Maybe the interaction already has been replied to."), "warn", true);
}
}
}
function findCommand(name, modules) {
for (const [, module] of modules) {
for (const part of module.parts) {
if ((part instanceof SlashCommand) && part.data.name == name)
return part;
}
}
}
//# sourceMappingURL=slashHandler.js.map