Update loaders, handlers, and BotClient to use centralized logger: - CommandLoader.ts and EventLoader.ts - AutocompleteHandler.ts, CommandHandler.ts, ComponentInteractionHandler.ts - BotClient.ts Provides consistent formatting across all core library logging.
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { ChatInputCommandInteraction, MessageFlags } from "discord.js";
|
|
import { AuroraClient } from "@/lib/BotClient";
|
|
import { userService } from "@/modules/user/user.service";
|
|
import { createErrorEmbed } from "@lib/embeds";
|
|
import { logger } from "@lib/logger";
|
|
|
|
/**
|
|
* Handles slash command execution
|
|
* Includes user validation and comprehensive error handling
|
|
*/
|
|
export class CommandHandler {
|
|
static async handle(interaction: ChatInputCommandInteraction): Promise<void> {
|
|
const command = AuroraClient.commands.get(interaction.commandName);
|
|
|
|
if (!command) {
|
|
logger.error(`No command matching ${interaction.commandName} was found.`);
|
|
return;
|
|
}
|
|
|
|
// Ensure user exists in database
|
|
try {
|
|
await userService.getOrCreateUser(interaction.user.id, interaction.user.username);
|
|
} catch (error) {
|
|
logger.error("Failed to ensure user exists:", error);
|
|
}
|
|
|
|
try {
|
|
await command.execute(interaction);
|
|
} catch (error) {
|
|
logger.error(String(error));
|
|
const errorEmbed = createErrorEmbed('There was an error while executing this command!');
|
|
|
|
if (interaction.replied || interaction.deferred) {
|
|
await interaction.followUp({ embeds: [errorEmbed], flags: MessageFlags.Ephemeral });
|
|
} else {
|
|
await interaction.reply({ embeds: [errorEmbed], flags: MessageFlags.Ephemeral });
|
|
}
|
|
}
|
|
}
|
|
}
|