commandbot
Version:
A framework that helps you create your own Discord bot easier.
158 lines (157 loc) • 5.55 kB
TypeScript
import { Message, Interaction, CommandInteractionOption } from "discord.js";
import { Parameter, ParameterSchema } from "../structures/Parameter.js";
import { ChatCommandObject } from "../structures/apiTypes.js";
import { ChildCommandInit, ChildCommandResolvable, ChildCommands, ChildCommandType } from "./commandsTypes.js";
import { CommandManager } from "../structures/CommandManager.js";
import { PermissionGuildCommand, PermissionGuildCommandInit } from "./base/PermissionGuildCommand.js";
import { SubCommand } from "./SubCommand.js";
import { InputManager } from "../structures/InputManager.js";
/**
* Intialization options of chat command
* @interface
* @extends {PermissionGuildCommandInit}
*/
export interface ChatCommandInit extends PermissionGuildCommandInit {
/**
* List of object defining all parameters of the command
* @type {?ParameterSchema[] | "simple" | "no_input"}
*/
parameters?: ParameterSchema[] | "simple" | "no_input";
/**
* Different string that can be used with prefix to invoke the command
* @type {?Array<string>}
*/
aliases?: string[] | string;
/**
* Command description
* @type {?string}
*/
description?: string;
/**
* Command usage (if *undefined*, the usage will be automatically generated using parameters)
* @type {?string}
*/
usage?: string;
/**
* Whether this command is visible in the help message
* @type {?boolean}
*/
visible?: boolean;
/**
* Whether this command should be registered as a slash command
* @type {?boolean}
*/
slash?: boolean;
}
/**
* A representation of CHAT_INPUT command (also known as a slash command)
* @class
* @extends {PermissionGuildCommand}
*/
export declare class ChatCommand extends PermissionGuildCommand {
/**
* Subcommands and groups of this command
* @type {Array<ChildCommandResolvable>}
* @private
* @readonly
*/
private readonly _children;
/**
* List of parameters that can passed to this command
* @type {Array<Parameter<any>>}
* @public
* @readonly
*/
readonly parameters: Parameter<any>[];
/**
* List of different names that can be used to invoke a command (when using prefix interactions)
* @type {?Array<string>}
* @public
* @readonly
*/
readonly aliases?: string[];
/**
* Command description displayed in the help message or in slash commands menu (Default description: "No description")
* @type {string}
* @public
* @readonly
*/
readonly description: string;
/**
* Command usage displayed in the help message
* @type {?string}
* @public
* @readonly
*/
readonly usage?: string;
/**
* Whether this command is visible in the help message (default: true)
* @type {boolean}
* @public
* @readonly
*/
readonly visible: boolean;
/**
* Whether this command should be registered as a slash command (default: true)
* @type {boolean}
* @public
* @readonly
*/
readonly slash: boolean;
/**
* ChatCommand constructor
* @constructor
* @param {CommandManager} manager - a manager that this command belongs to
* @param {ChatCommandInit} options - {@link ChatCommandInit} object containing all options needed to create a {@link ChatCommand}
*/
constructor(manager: CommandManager, options: ChatCommandInit);
/**
* Returns *true* if the command has subcommands attached
* @type {boolean}
*/
get hasSubCommands(): boolean;
/**
* Returns list of attached subcommands
* @type {Array<ChildCommandResolvable>}
* @readonly
*/
get children(): readonly ChildCommandResolvable[];
/**
* Invoke the command
* @param {InputManager} input - input data manager
* @returns {Promise<void>}
* @public
* @async
*/
start(input: InputManager): Promise<void>;
/**
* Attaches subcommand or subcommand group to this ChatCommand
* @param {T} type - subcommand type
* @param {ChildCommandInit<T>} options - initialization options
* @returns {ChildCommands<T>} A computed subcommand object
* @public
* @remarks After appending a subcommand or a subcommand group the main command can only be invoked using prefix interactions
*/
append<T extends ChildCommandType>(type: T, options: ChildCommandInit<T>): ChildCommands<T>;
/**
*
* @param {Array<CommandInteractionOption>} options - parameter options
* @param {Interaction | Message} interaction - Discord interaction
* @returns {?InputManager} an {@link InputManager} containing all interaction-related data or *null*
* @public
*/
fetchSubcommand(options: CommandInteractionOption[], interaction: Interaction | Message): InputManager | null;
/**
*
* @param {string} name - subcommand name
* @param {?string} [group] - name of the group (if any)
* @returns {?SubCommand} a {@link SubCommand} object or *null*
*/
getSubcommand(name: string, group?: string): SubCommand | null;
/**
* Converts {@link ChatCommand} instance to object that is recognized by the Discord API
* @returns {ChatCommandObject} Discord API object
* @public
*/
toObject(): ChatCommandObject;
}