simplify-cord
Version:
SimplifyCord is an unofficial extension of the 'discord.js' library. Our extension aims to simplify the development of Discord bots, promoting cleaner code and easier maintenance.
36 lines (31 loc) • 1.58 kB
text/typescript
import { ApplicationCommandOption, ApplicationCommandType, AutocompleteInteraction, CommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction } from "discord.js";
import { bootstrapApp } from "../../class/Client";
import chalk from 'chalk';
export const slashCommandHandlers = new Map();
type CommandInteractionType<T> =
T extends ApplicationCommandType.ChatInput ? CommandInteraction :
T extends ApplicationCommandType.User ? UserContextMenuCommandInteraction :
T extends ApplicationCommandType.Message ? MessageContextMenuCommandInteraction :
never;
export interface ISlashCommandHandler<T extends ApplicationCommandType = ApplicationCommandType> {
name: string;
description?: T extends ApplicationCommandType.ChatInput ? string : undefined;
type: T;
options?: ApplicationCommandOption[];
autocomplete?: (interaction: AutocompleteInteraction) => any,
run: (client: bootstrapApp, interaction: CommandInteractionType<T>) => any;
}
export default class SlashCommand<T extends ApplicationCommandType> {
constructor(data: ISlashCommandHandler<T>) {
if (slashCommandHandlers.has(data.name)) {
console.log(chalk.yellow(`⚠ Warning: Command "${data.name}" is being registered more than once!`));
return;
}
slashCommandHandlers.set(data.name, data);
}
public static loadLogs() {
for (const [name] of slashCommandHandlers) {
console.log(chalk.green(`{/} ${chalk.blue.underline(name)} command loaded!`));
}
}
}