UNPKG

djs-message-commands

Version:

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

117 lines (116 loc) 4.79 kB
import { Message, PermissionResolvable } from "discord.js"; import { MessageCommandBooleanOption, MessageCommandChannelOption, MessageCommandMemberOption, MessageCommandNumberOption, MessageCommandOption, MessageCommandRoleOption, MessageCommandStringOption } from "./"; import { MessageCommandOptionError } from "./MessageCommandOption"; export interface MessageCommandBuilderData { name: string; description: string; aliases?: string[]; options?: MessageCommandOption[]; roleIds?: string[]; permissions?: PermissionResolvable[]; } export declare class MessageCommandBuilder { /** * The name of the command. */ name: string; /** * The description of the command. */ description: string; /** * Any aliases the command may be executed with. */ aliases: string[]; /** * The options/arguments that can be supplied to this command. */ options: MessageCommandOption[]; /** * The role IDs permitted to execute this command. */ roleIds: string[]; /** * The permissions permitted to execute this command. */ permissions: PermissionResolvable[]; constructor(data?: MessageCommandBuilderData); /** * Sets the name of the command. Cannot be empty. * @param name The name of the command. * @returns The builder instance. */ setName(name: string): this; /** * Sets the description of the command. Cannot be empty. * @param description The description of the command. * @returns The builder instance. */ setDescription(description: string): this; /** * Sets any aliases you wish to supply for the command. * @param aliases The aliases of the command. * @returns The builder instance. */ setAliases(aliases: string[]): this; /** * Sets the roles allowed to execute this command. If a role doesn't exist in the guild, it will be ignored. * @param ids The role IDs permitted to execute this command. * @returns The builder instance. */ setRoles(ids: string[]): this; /** * Sets the permissions allowed to execute this command. * @param permissions The permissions required to execute this command. * @returns The builder instance. */ setPermissions(permissions: PermissionResolvable[]): this; /** * Adds a choice-able string option to the command. * @param composer A function that returns an instance of the option. * @returns The builder instance. */ addStringOption(composer: (option: MessageCommandStringOption) => MessageCommandStringOption): this; /** * Adds a choice-able number option to the command. * @param composer A function that returns an instance of the option. * @returns The builder instance. */ addNumberOption(composer: (option: MessageCommandNumberOption) => MessageCommandNumberOption): this; /** * Adds a boolean option to the command. * @param composer A function that returns an instance of the option. * @returns The builder instance. */ addBooleanOption(composer: (option: MessageCommandBooleanOption) => MessageCommandBooleanOption): this; /** * Adds a member mentionable option to the command. * @param composer A function that returns an instance of the option. * @returns The builder instance. */ addMemberOption(composer: (option: MessageCommandMemberOption) => MessageCommandMemberOption): this; /** * Adds a channel mentionable option to the command. * @param composer A function that returns an instance of the option. * @returns The builder instance. */ addChannelOption(composer: (option: MessageCommandChannelOption) => MessageCommandChannelOption): this; /** * Adds a role mentionable option to the command. * @param composer A function that returns an instance of the option. * @returns The builder instance. */ addRoleOption(composer: (option: MessageCommandRoleOption) => MessageCommandRoleOption): this; /** * A utility method to convert the command into a regular expression. Useful for debugging. * @param prefix The guild's message prefix. * @returns The command's builder converted to RegExp. */ toRegex(prefix: string): RegExp; /** * Validates the message with the command. This checks for permissions, roles, and arguments supplied to the command. * @param message The message to validate. * @returns The parsed options and potential errors. */ validate(message: Message): readonly [MessageCommandOptionError[] | undefined, unknown[]]; }