UNPKG

@dookdiks/discord-bot-builder

Version:
32 lines (31 loc) 921 B
import { SlashCommandBuilder, Events, } from "discord.js"; import { BaseEventHandler } from "./BaseEventHandler"; export class CreateInteractionEvent extends BaseEventHandler { slashCommand = new SlashCommandBuilder(); handler; command(builder) { this.slashCommand = builder(this.slashCommand); return this; } on(handler) { this.handler = handler; return this; } getSlashCommand() { return this.slashCommand; } getHandler() { return this.handler; } register() { if (!this.client || !this.handler) return; this.client.on(Events.InteractionCreate, async (interaction) => { if (!interaction.isChatInputCommand()) return; if (interaction.commandName === this.slashCommand.name) { await this.handler?.(interaction); } }); } }