diff --git a/src/lib/BotClient.ts b/src/lib/BotClient.ts index 9acc052..b97404d 100644 --- a/src/lib/BotClient.ts +++ b/src/lib/BotClient.ts @@ -4,6 +4,7 @@ import type { Command } from "@lib/types"; import { env } from "@lib/env"; import { CommandLoader } from "@lib/loaders/CommandLoader"; import { EventLoader } from "@lib/loaders/EventLoader"; +import { logger } from "@lib/logger"; export class Client extends DiscordClient { @@ -21,25 +22,25 @@ export class Client extends DiscordClient { async loadCommands(reload: boolean = false) { if (reload) { this.commands.clear(); - console.log("♻️ Reloading commands..."); + logger.info("♻️ Reloading commands..."); } const commandsPath = join(import.meta.dir, '../commands'); const result = await this.commandLoader.loadFromDirectory(commandsPath, reload); - console.log(`📦 Command loading complete: ${result.loaded} loaded, ${result.skipped} skipped, ${result.errors.length} errors`); + logger.info(`📦 Command loading complete: ${result.loaded} loaded, ${result.skipped} skipped, ${result.errors.length} errors`); } async loadEvents(reload: boolean = false) { if (reload) { this.removeAllListeners(); - console.log("♻️ Reloading events..."); + logger.info("♻️ Reloading events..."); } const eventsPath = join(import.meta.dir, '../events'); const result = await this.eventLoader.loadFromDirectory(eventsPath, reload); - console.log(`📦 Event loading complete: ${result.loaded} loaded, ${result.skipped} skipped, ${result.errors.length} errors`); + logger.info(`📦 Event loading complete: ${result.loaded} loaded, ${result.skipped} skipped, ${result.errors.length} errors`); } @@ -48,7 +49,7 @@ export class Client extends DiscordClient { // We use env.DISCORD_BOT_TOKEN directly so this can run without client.login() const token = env.DISCORD_BOT_TOKEN; if (!token) { - console.error("❌ DISCORD_BOT_TOKEN is not set."); + logger.error("DISCORD_BOT_TOKEN is not set."); return; } @@ -58,16 +59,16 @@ export class Client extends DiscordClient { const clientId = env.DISCORD_CLIENT_ID; if (!clientId) { - console.error("❌ DISCORD_CLIENT_ID is not set."); + logger.error("DISCORD_CLIENT_ID is not set."); return; } try { - console.log(`Started refreshing ${commandsData.length} application (/) commands.`); + logger.info(`Started refreshing ${commandsData.length} application (/) commands.`); let data; if (guildId) { - console.log(`Registering commands to guild: ${guildId}`); + logger.info(`Registering commands to guild: ${guildId}`); data = await rest.put( Routes.applicationGuildCommands(clientId, guildId), { body: commandsData }, @@ -75,20 +76,20 @@ export class Client extends DiscordClient { // Clear global commands to avoid duplicates await rest.put(Routes.applicationCommands(clientId), { body: [] }); } else { - console.log('Registering commands globally'); + logger.info('Registering commands globally'); data = await rest.put( Routes.applicationCommands(clientId), { body: commandsData }, ); } - console.log(`✅ Successfully reloaded ${(data as any).length} application (/) commands.`); + logger.success(`Successfully reloaded ${(data as any).length} application (/) commands.`); } catch (error: any) { if (error.code === 50001) { - console.warn("⚠️ Missing Access: The bot is not in the guild or lacks 'applications.commands' scope."); - console.warn(" If you are testing locally, make sure you invited the bot with scope 'bot applications.commands'."); + logger.warn("Missing Access: The bot is not in the guild or lacks 'applications.commands' scope."); + logger.warn(" If you are testing locally, make sure you invited the bot with scope 'bot applications.commands'."); } else { - console.error(error); + logger.error(error); } } } diff --git a/src/lib/handlers/AutocompleteHandler.ts b/src/lib/handlers/AutocompleteHandler.ts index ce56285..8993e68 100644 --- a/src/lib/handlers/AutocompleteHandler.ts +++ b/src/lib/handlers/AutocompleteHandler.ts @@ -1,5 +1,6 @@ import { AutocompleteInteraction } from "discord.js"; import { AuroraClient } from "@/lib/BotClient"; +import { logger } from "@lib/logger"; /** * Handles autocomplete interactions for slash commands @@ -15,7 +16,7 @@ export class AutocompleteHandler { try { await command.autocomplete(interaction); } catch (error) { - console.error(`Error handling autocomplete for ${interaction.commandName}:`, error); + logger.error(`Error handling autocomplete for ${interaction.commandName}:`, error); } } } diff --git a/src/lib/handlers/CommandHandler.ts b/src/lib/handlers/CommandHandler.ts index e4fca44..0c82411 100644 --- a/src/lib/handlers/CommandHandler.ts +++ b/src/lib/handlers/CommandHandler.ts @@ -2,6 +2,7 @@ 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 @@ -12,7 +13,7 @@ export class CommandHandler { const command = AuroraClient.commands.get(interaction.commandName); if (!command) { - console.error(`No command matching ${interaction.commandName} was found.`); + logger.error(`No command matching ${interaction.commandName} was found.`); return; } @@ -20,13 +21,13 @@ export class CommandHandler { try { await userService.getOrCreateUser(interaction.user.id, interaction.user.username); } catch (error) { - console.error("Failed to ensure user exists:", error); + logger.error("Failed to ensure user exists:", error); } try { await command.execute(interaction); } catch (error) { - console.error(error); + logger.error(String(error)); const errorEmbed = createErrorEmbed('There was an error while executing this command!'); if (interaction.replied || interaction.deferred) { diff --git a/src/lib/handlers/ComponentInteractionHandler.ts b/src/lib/handlers/ComponentInteractionHandler.ts index b317df1..edaeb62 100644 --- a/src/lib/handlers/ComponentInteractionHandler.ts +++ b/src/lib/handlers/ComponentInteractionHandler.ts @@ -1,4 +1,5 @@ import { ButtonInteraction, StringSelectMenuInteraction, ModalSubmitInteraction } from "discord.js"; +import { logger } from "@lib/logger"; type ComponentInteraction = ButtonInteraction | StringSelectMenuInteraction | ModalSubmitInteraction; @@ -19,7 +20,7 @@ export class ComponentInteractionHandler { await handlerMethod(interaction); return; } else { - console.error(`Handler method ${route.method} not found in module`); + logger.error(`Handler method ${route.method} not found in module`); } } } diff --git a/src/lib/loaders/CommandLoader.ts b/src/lib/loaders/CommandLoader.ts index 0a76519..cdaa94d 100644 --- a/src/lib/loaders/CommandLoader.ts +++ b/src/lib/loaders/CommandLoader.ts @@ -4,6 +4,7 @@ import type { Command } from "@lib/types"; import { config } from "@lib/config"; import type { LoadResult, LoadError } from "./types"; import type { Client } from "../BotClient"; +import { logger } from "@lib/logger"; /** * Handles loading commands from the file system @@ -44,7 +45,7 @@ export class CommandLoader { await this.loadCommandFile(filePath, reload, result); } } catch (error) { - console.error(`Error reading directory ${dir}:`, error); + logger.error(`Error reading directory ${dir}:`, error); result.errors.push({ file: dir, error }); } } @@ -59,7 +60,7 @@ export class CommandLoader { const commands = Object.values(commandModule); if (commands.length === 0) { - console.warn(`⚠️ No commands found in ${filePath}`); + logger.warn(`No commands found in ${filePath}`); result.skipped++; return; } @@ -73,21 +74,21 @@ export class CommandLoader { const isEnabled = config.commands[command.data.name] !== false; if (!isEnabled) { - console.log(`🚫 Skipping disabled command: ${command.data.name}`); + logger.info(`🚫 Skipping disabled command: ${command.data.name}`); result.skipped++; continue; } this.client.commands.set(command.data.name, command); - console.log(`✅ Loaded command: ${command.data.name}`); + logger.success(`Loaded command: ${command.data.name}`); result.loaded++; } else { - console.warn(`⚠️ Skipping invalid command in ${filePath}`); + logger.warn(`Skipping invalid command in ${filePath}`); result.skipped++; } } } catch (error) { - console.error(`❌ Failed to load command from ${filePath}:`, error); + logger.error(`Failed to load command from ${filePath}:`, error); result.errors.push({ file: filePath, error }); } } diff --git a/src/lib/loaders/EventLoader.ts b/src/lib/loaders/EventLoader.ts index 9619d77..c81c912 100644 --- a/src/lib/loaders/EventLoader.ts +++ b/src/lib/loaders/EventLoader.ts @@ -3,6 +3,7 @@ import { join } from "node:path"; import type { Event } from "@lib/types"; import type { LoadResult } from "./types"; import type { Client } from "../BotClient"; +import { logger } from "@lib/logger"; /** * Handles loading events from the file system @@ -43,7 +44,7 @@ export class EventLoader { await this.loadEventFile(filePath, reload, result); } } catch (error) { - console.error(`Error reading directory ${dir}:`, error); + logger.error(`Error reading directory ${dir}:`, error); result.errors.push({ file: dir, error }); } } @@ -63,14 +64,14 @@ export class EventLoader { } else { this.client.on(event.name, (...args) => event.execute(...args)); } - console.log(`✅ Loaded event: ${event.name}`); + logger.success(`Loaded event: ${event.name}`); result.loaded++; } else { - console.warn(`⚠️ Skipping invalid event in ${filePath}`); + logger.warn(`Skipping invalid event in ${filePath}`); result.skipped++; } } catch (error) { - console.error(`❌ Failed to load event from ${filePath}:`, error); + logger.error(`Failed to load event from ${filePath}:`, error); result.errors.push({ file: filePath, error }); } }