import { ApplicationCommandOptionType, ApplicationCommandType, AutocompleteInteraction, ChatInputCommandInteraction, InteractionContextType, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, type ApplicationCommandOptionAllowedChannelTypes, type ApplicationCommandOptionChoiceData, type BaseApplicationCommandData, type CacheType, type LocalizationMap } from "discord.js"; import type { NotEmptyArray, UniqueArray } from "../../utils/types.js"; export type CommandType = ApplicationCommandType.ChatInput | ApplicationCommandType.Message | ApplicationCommandType.User; type AutocompleData = Promise[] | undefined | void>; export type AutocompleteRun = (this: void, interaction: AutocompleteInteraction>) => AutocompleData; interface AutocompleteOptionData { autocomplete?: true | AutocompleteRun; } interface BaseOptionData { name: string; nameLocalizations?: LocalizationMap; description?: string; descriptionLocalizations?: LocalizationMap; required?: boolean; } interface StringOptionData extends BaseOptionData, AutocompleteOptionData { type: ApplicationCommandOptionType.String; choices?: readonly ApplicationCommandOptionChoiceData[]; minLength?: number; maxLength?: number; } interface NumberOptionData extends BaseOptionData, AutocompleteOptionData { type: ApplicationCommandOptionType.Number | ApplicationCommandOptionType.Integer; choices?: readonly ApplicationCommandOptionChoiceData[]; minValue?: number; maxValue?: number; } interface ChannelOptionData extends BaseOptionData { type: ApplicationCommandOptionType.Channel; channelTypes?: readonly ApplicationCommandOptionAllowedChannelTypes[]; } interface CommonOptionData extends BaseOptionData { type: ApplicationCommandOptionType.Attachment | ApplicationCommandOptionType.Boolean | ApplicationCommandOptionType.Mentionable | ApplicationCommandOptionType.Role | ApplicationCommandOptionType.User; } export type SlashCommandPrimitiveOptionData = StringOptionData | NumberOptionData | CommonOptionData | ChannelOptionData; export interface SubCommandOptionData extends Omit { type: ApplicationCommandOptionType.Subcommand; options?: SlashCommandPrimitiveOptionData[]; } export interface GroupOptionData extends Omit { type: ApplicationCommandOptionType.SubcommandGroup; options: SubCommandOptionData[]; } type CacheMode = Contexts extends readonly InteractionContextType[] ? { [InteractionContextType.Guild]: "cached"; [InteractionContextType.BotDM]: CacheType; [InteractionContextType.PrivateChannel]: CacheType; }[Contexts[number]] : CacheType; interface CommandRunThis { /** * Blocks the flow of executions */ block(): never; } type ResolveCommandModuleData = Return extends void ? undefined : Return; export type SubCommandModuleData = Omit & { group?: string; run(this: CommandRunThis, interaction: ChatInputCommandInteraction>, data: ResolveCommandModuleData): Promise; options?: SlashCommandPrimitiveOptionData[]; }; export type SubCommandGroupModuleData = Omit & { options?: Omit, "type">[]; run?(this: CommandRunThis, interaction: ChatInputCommandInteraction>, data: ResolveCommandModuleData): Promise; }; type RunInteraction = T extends ApplicationCommandType.Message ? MessageContextMenuCommandInteraction> : T extends ApplicationCommandType.User ? UserContextMenuCommandInteraction> : ChatInputCommandInteraction>; type BaseAppCommandData = Omit & Pick; export interface CommandData extends BaseAppCommandData { name: string; description?: string; contexts?: NotEmptyArray>; type?: T; global?: boolean; run?(this: CommandRunThis, interaction: RunInteraction): Promise; autocomplete?: AutocompleteRun; options?: SlashCommandPrimitiveOptionData[] | (GroupOptionData | SubCommandOptionData)[]; } export type SlashCommandOptionData = SlashCommandPrimitiveOptionData | GroupOptionData | SubCommandOptionData; export type CommandModule = (SubCommandGroupModuleData & { type: ApplicationCommandOptionType.SubcommandGroup; }) | (SubCommandModuleData & { type: ApplicationCommandOptionType.Subcommand; group?: string; }); declare class GroupCommandModule { readonly command: Command; readonly data: SubCommandGroupModuleData; constructor(command: Command, data: SubCommandGroupModuleData); subcommand(data: SubCommandModuleData): this; } export declare class Command { readonly data: CommandData; readonly modules: CommandModule[]; constructor(data: CommandData); group(data: SubCommandGroupModuleData): GroupCommandModule; subcommand(data: SubCommandModuleData): this; } export {};