feat(polish): Adds EmbedLibrary

This commit is contained in:
Michel Fedde 2025-06-24 21:59:55 +02:00
parent cf9c88a2d6
commit b3d0b3a90c
12 changed files with 240 additions and 136 deletions

View file

@ -3,7 +3,7 @@ import {
AutocompleteInteraction, ButtonInteraction,
ChatInputCommandInteraction,
inlineCode,
Interaction,
Interaction, InteractionReplyOptions,
MessageFlags, ModalSubmitInteraction,
} from "discord.js";
import Commands from "./Commands/Commands";
@ -15,6 +15,7 @@ import {ModalInteractionEvent} from "../Events/EventClasses/ModalInteractionEven
import {ComponentInteractionEvent} from "../Events/EventClasses/ComponentInteractionEvent";
import {log} from "node:util";
import {PermissionError} from "./PermissionError";
import {EmbedLibrary} from "./EmbedLibrary";
enum InteractionRoutingType {
Unrouted,
@ -94,24 +95,27 @@ export class InteractionRouter {
await command.execute?.call(command, interaction);
} catch (e: any) {
let userMessage = ":x: There was an error while executing this command!";
let logErrorMessage = true;
if ("getDiscordMessage" in e) {
userMessage = e.getDiscordMessage(e);
}
if ("shouldLog" in e) {
logErrorMessage = e.shouldLog;
}
}
if (logErrorMessage) {
this.logger.error(e)
}
const responseOptions: InteractionReplyOptions = {
embeds: [
EmbedLibrary.error(e)
],
flags: MessageFlags.Ephemeral
}
if (interaction.replied || interaction.deferred) {
await interaction.followUp({content: userMessage, flags: MessageFlags.Ephemeral});
await interaction.followUp(responseOptions);
} else {
await interaction.reply({content: userMessage, flags: MessageFlags.Ephemeral});
await interaction.reply(responseOptions);
}
}
}