relay/src/bot/handlers/events.ts
Corban-Lee Jones 99ebb9a578
All checks were successful
Build / build (push) Successful in 1m4s
chore: resolve all eslint errors
2025-05-15 21:33:57 +01:00

32 lines
991 B
TypeScript

import { join } from "path";
import { Collection } from "discord.js";
import getAllFiles from "@bot/utils/getAllFiles";
import Event from "@bot/components/event";
import DiscordBot from "@bot/bot";
export default class EventHandler extends Collection<string, Event> {
readonly client: DiscordBot;
constructor(client: DiscordBot) {
super();
this.client = client
this.init();
}
private async init() {
const eventsDirectory = join(__dirname, "../events");
const modules = getAllFiles(eventsDirectory);
for (const module of modules) {
const imported = await import(module);
const eventClass = imported.default || imported;
const event: Event = new eventClass(this.client);
this.set(event.name, event);
this.client[event.once ? "once" : "on"](
event.name,
(...args: unknown[]) => event.execute(...args)
);
}
}
}