@dookdiks/discord-bot-builder
Version:
Modular Discord bot builder using discord.js
32 lines (31 loc) • 921 B
JavaScript
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);
}
});
}
}