UNPKG

djs-message-commands

Version:

Build easy, safe, and testable message commands for discord.js

140 lines (139 loc) 4.57 kB
import { Snowflake } from "discord.js"; export interface MessageCommandOptionData { name: string; description: string; readonly type: MessageCommandOptionType; } /** * A composable option/argument to add to a message command. * @abstract */ export declare abstract class MessageCommandOption { /** * The name of the option. */ name: string; /** * The description of the option. */ description: string; /** * The type of the option. */ readonly type: MessageCommandOptionType; constructor(data: MessageCommandOptionType | MessageCommandOptionData); /** * Sets the name of the option. Cannot be empty. * @param name The name of the option. * @returns The option instance. */ setName(name: string): this; /** * Sets the name of the option. Cannot be empty. * @param description The description of the option. * @returns The option instance. */ setDescription(description: string): this; /** * Performs a type-specific validation on the option. * @param option The option to compare to. */ abstract validate(option: string): unknown; } /** * A option that can be supplied with pre-defined values for the user to choose from. * @abstract * @extends MessageCommandOption */ export declare abstract class MessageCommandOptionChoiceable<T extends string | number> extends MessageCommandOption { /** * The available pre-determined choices for this option. */ choices: MessageCommandOptionChoice<T>[]; constructor(type: MessageCommandOptionType); /** * Add a choice for this option. Chain this multiple times to add more options OR use {@link MessageCommandOptionChoiceable.setChoices}. * @param choice The choice to add. * @returns The option instance. */ addChoice(...choice: MessageCommandOptionChoice<T>): this; /** * Add multiple choices for this option. Use this either once OR chain {@link MessageCommandOptionChoiceable.addChoice}. * @param choices The choices to add. * @returns The option instance. */ setChoices(choices: MessageCommandOptionChoice<T>[]): this; } /** * A string option. Allows choices. * @extends MessageCommandOptionChoiceable */ export declare class MessageCommandStringOption extends MessageCommandOptionChoiceable<string> { constructor(); validate(option: string): string | undefined; } /** * A number option. Allows choices. * @extends MessageCommandOptionChoiceable */ export declare class MessageCommandNumberOption extends MessageCommandOptionChoiceable<number> { constructor(); validate(option: string): number | undefined; } /** * A boolean option. * @extends MessageCommandOption */ export declare class MessageCommandBooleanOption extends MessageCommandOption { constructor(); validate(option: string): boolean | undefined; } /** * A member mentionable option. * @extends MessageCommandOption */ export declare class MessageCommandMemberOption extends MessageCommandOption { constructor(); validate(option: string): Snowflake | undefined; } /** * A channel mentionable option. * @extends MessageCommandOption */ export declare class MessageCommandChannelOption extends MessageCommandOption { constructor(); validate(option: string): Snowflake | undefined; } /** * A role mentionable option. * @extends MessageCommandOption */ export declare class MessageCommandRoleOption extends MessageCommandOption { constructor(); validate(option: string): Snowflake | undefined; } /** * An enum containing user-friendly values for each option type. */ export declare const enum MessageCommandOptionType { BOOLEAN = "true/false", NUMBER = "number", STRING = "text", MEMBER = "member", CHANNEL = "channel", ROLE = "role" } /** * A tuple containing both the name and value for each option choice. */ export declare type MessageCommandOptionChoice<ValueType extends string | number> = [name: string, value: ValueType]; export interface MessageCommandOptionError { message: string; type: keyof typeof MessageCommandOptionErrors; } export declare const MessageCommandOptionErrors: { readonly INVALID_ARG_TYPE: "INVALID_ARG_TYPE"; readonly MISSING_ARGS: "MISSING_ARGS"; readonly MISSING_PERMISSIONS: "MISSING_PERMISSIONS"; readonly MISSING_ROLES: "MISSING_ROLES"; };