지금까지 내용 커밋
This commit is contained in:
25
bot/src/classes/Handler.ts
Normal file
25
bot/src/classes/Handler.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ChatInputCommandInteraction, Collection } from "discord.js";
|
||||
import { readdirSync } from "node:fs";
|
||||
import { Command } from "../types/Command";
|
||||
import { COMMAND_PATH, COMMANDS_PATH } from "../utils/Config";
|
||||
|
||||
export class Handler {
|
||||
public commands: Collection<string, Command> = new Collection();
|
||||
public coolDown: Map<string, number> = 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 runCommand(interaction: ChatInputCommandInteraction) {
|
||||
const commandName = interaction.commandName;
|
||||
const command = this.commands.get(commandName);
|
||||
|
||||
if (!command) return;
|
||||
if (command.slashRun) command.slashRun(interaction);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user