import { ChatInputCommandInteraction, Collection } from "discord.js"; import { readdirSync } from "node:fs"; import { Command } from "../types/Command"; import { COMMAND_PATH, COMMANDS_PATH } from "../utils/Config"; import { Logger } from "../utils/Logger"; export class Handler { public commands: Collection = new Collection(); public coolDown: Map = new Map(); public constructor() { const commandFiles = readdirSync(COMMANDS_PATH); for (const commandFile of commandFiles) { const command = new (require(COMMAND_PATH(commandFile)).default)() as Command; this.commands.set(command.metaData.name, command); } } public async runCommand(interaction: ChatInputCommandInteraction) { const commandName = interaction.commandName; const command = this.commands.get(commandName); if (!command) return; try { if (command.slashRun) await command.slashRun(interaction); } catch (err) { Logger.error(`[Handler] 명령어 '${commandName}' 실행 중 에러: ${String(err)}`); await interaction.editReply({ content: "명령어 실행 중 오류가 발생했습니다." }).catch(() => {}); } } }