Build/project structure #142

Merged
BlackAngelTV merged 80 commits from build/project-structure into main 2026-09-23 14:31:21 +02:00
Showing only changes of commit 017764d5b8 - Show all commits
+47
View File
@@ -0,0 +1,47 @@
import { Events, MessageFlags } from 'discord.js';
import { PermissionDeniedError, UserFacingError } from '../core/errors.js';
import { createLogger } from '../core/logger.js';
import { hasAccess } from '../core/permissions.js';
import { errorEmbed } from '../ui/embeds.js';
const log = createLogger('interactions');
export const name = Events.InteractionCreate;
async function replyError(interaction, message) {
const payload = { embeds: [errorEmbed(message)], flags: MessageFlags.Ephemeral };
if (interaction.deferred || interaction.replied) {
await interaction.followUp(payload);
} else {
await interaction.reply(payload);
}
}
export async function execute(client, interaction) {
if (!interaction.isChatInputCommand() && !interaction.isAutocomplete()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
if (interaction.isAutocomplete()) {
await command.autocomplete?.(interaction);
return;
}
try {
const subcommand = interaction.options.getSubcommand(false);
const requiredLevel = command.subcommandAccess?.[subcommand] ?? command.access;
if (!hasAccess(interaction.member, requiredLevel)) {
throw new PermissionDeniedError();
}
await command.execute(interaction);
} catch (error) {
if (error instanceof UserFacingError) {
await replyError(interaction, error.message);
return;
}
log.error(`Command failed: /${interaction.commandName}`, error);
await replyError(interaction, 'Une erreur inattendue est survenue. Réessaie plus tard.').catch(() => {});
}
}