dressed
Version:
A sleek, serverless-ready Discord bot framework.
53 lines (52 loc) • 2.98 kB
TypeScript
import { type APIApplicationCommandInteractionDataOption, type APIAttachment, type APIInteractionDataResolved, type APIInteractionDataResolvedChannel, type APIRole, type APIUser } from "discord-api-types/v10";
import type { ChatInputConfig } from "../../types/config.ts";
import type { CommandInteraction, GetOptionFn } from "../../types/interaction.ts";
import type { Requirable } from "../../types/utilities.ts";
export interface OptionValueGetters<N extends string, T extends Pick<ChatInputConfig, "options"> | undefined = undefined> {
/** Return the option as a subcommand - Option type must be `Subcommand` */
subcommand: () => {
/**
* Get an option from the subcommand
* @param name The name of the option
* @param required Whether the option is required
*/
getOption: T extends object ? GetOptionFn<T & {
description: string;
}> : CommandInteraction["getOption"];
name: N;
};
/** Return the option as a subcommand group - Option type must be `SubcommandGroup` */
subcommandGroup: () => {
/**
* Get a subcommand from the group
* @param name The name of the subcommand
*/
getSubcommand: T extends object ? <N extends NonNullable<T["options"]>[number]["name"], O extends Extract<NonNullable<T["options"]>[number], {
name: N;
}>>(name: N) => ReturnType<OptionValueGetters<N, {
options: O extends {
options: unknown[];
} ? O["options"] : [];
}>["subcommand"]> | undefined : <N extends string>(name: N) => ReturnType<OptionValueGetters<N>["subcommand"]> | undefined;
name: N;
};
/** Return the option's value as a string - Option type must be `String` */
string: () => string;
/** Return the option's value as an integer - Option type must be `Integer` */
integer: () => number;
/** Return the option's value as a boolean - Option type must be `Boolean` */
boolean: () => boolean;
/** Get the user from the option - Option type must be `User` */
user: () => APIUser;
/** Get the channel from the option - Option type must be `Channel` */
channel: () => APIInteractionDataResolvedChannel;
/** Get the role from the option - Option type must be `Role` */
role: () => APIRole;
/** Get the mentionable from the option - Option type must be `Mentionable` */
mentionable: () => APIUser | APIRole;
/** Return the option's value as a number - Option type must be `Number` */
number: () => number;
/** Get the attachment from the option - Option type must be `Attachment` */
attachment: () => APIAttachment;
}
export declare function getOption<N extends string, R extends boolean, T extends ChatInputConfig | undefined = undefined>(name: N, required: R, options: APIApplicationCommandInteractionDataOption[], resolved?: APIInteractionDataResolved): Requirable<R, OptionValueGetters<N, T>>;