42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
|
import { PermissionsBitField } from "discord.js";
|
||
|
import { RESTPostAPIApplicationCommandsJSONBody } from "discord.js";
|
||
|
import { ApplicationCommandOption, ApplicationCommandType, ChatInputCommandInteraction, LocalizationMap, MessageInteraction, PermissionResolvable, UserSelectMenuInteraction } from "discord.js";
|
||
|
|
||
|
type InteractionTypeMap = {
|
||
|
[ApplicationCommandType.ChatInput]: [ChatInputCommandInteraction, string];
|
||
|
[ApplicationCommandType.Message]: [MessageInteraction, never];
|
||
|
[ApplicationCommandType.User]: [UserSelectMenuInteraction, never];
|
||
|
};
|
||
|
|
||
|
interface Command<Type extends keyof InteractionTypeMap = ApplicationCommandType> {
|
||
|
readonly name: string;
|
||
|
readonly name_localizations?: LocalizationMap;
|
||
|
readonly description: InteractionTypeMap[Type][1];
|
||
|
readonly description_localizations?: LocalizationMap;
|
||
|
readonly options?: ApplicationCommandOption[];
|
||
|
readonly default_member_permissions?: PermissionResolvable;
|
||
|
readonly type: Type;
|
||
|
readonly nsfw?: boolean;
|
||
|
readonly dm_permission?: boolean;
|
||
|
}
|
||
|
|
||
|
abstract class Command<Type extends keyof InteractionTypeMap = ApplicationCommandType> {
|
||
|
abstract execute(interaction: InteractionTypeMap[Type][0]): Promise<void>;
|
||
|
|
||
|
toRESTPostApplicationCommands(): RESTPostAPIApplicationCommandsJSONBody {
|
||
|
return {
|
||
|
name: this.name,
|
||
|
name_localizations: this.name_localizations,
|
||
|
description: this.description,
|
||
|
description_localizations: this.description_localizations,
|
||
|
options: this.options,
|
||
|
default_member_permissions: this.default_member_permissions !== undefined ? new PermissionsBitField(this.default_member_permissions).bitfield.toString() : undefined,
|
||
|
type: this.type,
|
||
|
nsfw: this.nsfw,
|
||
|
dm_permission: this.dm_permission,
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default Command;
|