UNPKG

commandbot

Version:

A framework that helps you create your own Discord bot easier.

93 lines (92 loc) 3.86 kB
import { APICommandInit, Command } from "./Command.js"; import { CommandManager } from "../../structures/CommandManager.js"; import { CommandFunction, CommandType, EphemeralType } from "../commandsTypes.js"; import { InputManager } from "../../structures/InputManager.js"; /** * Initialization options of base executable command * @interface * @extends {APICommandInit} */ export interface FunctionCommandInit extends APICommandInit { /** * Command function (will be executed when calling a command) * @type {?CommandFunction} */ function?: CommandFunction; /** * Whether to send a built-in success message when the command has completed (if no other response is defined) * @type {?boolean} */ announceSuccess?: boolean; /** * Whether a reply should be visible only to the caller * * - NONE - bot replies are public and visible to everyone in a text channel * - INTERACTIONS - bot will mark responses to Discord interactions as ephemeral and they will only be visible to the command caller * - FULL - INTERACTIONS + responses to prefix interactions will be sent as direct messages to the command caller * * [Read more](https://support.discord.com/hc/pl/articles/1500000580222-Ephemeral-Messages-FAQ) * @type {?EphemeralType} */ ephemeral?: EphemeralType; } /** * Function (executable) command * @class * @extends {Command} */ export declare class FunctionCommand extends Command { /** * Command function (called on command execution) * @type {CommandFunction} * @private * @readonly */ private readonly _function; /** * Whether a SUCCESS message should be sent after executing the command function (when there is no other reply) * @type {boolean} * @public * @readonly */ readonly announceSuccess: boolean; /** * Whether a reply should be visible only to the caller * * - NONE - bot replies are public and visible to everyone in a text channel * - INTERACTIONS - bot will mark responses to Discord interactions as ephemeral and they will only be visible to the command caller * - FULL - INTERACTIONS + responses to prefix interactions will be sent as direct messages to the command caller * * [Read more](https://support.discord.com/hc/pl/articles/1500000580222-Ephemeral-Messages-FAQ) * @type {EphemeralType} * @public * @readonly * @remarks Since ephemeral interactions cannot be deleted, a placeholding embed will be sent when there will be no response from the command function and _announceSuccess_ will be set to false (placeholding message uses _color_ and _title_ parameters from SUCCESS system message configuration) */ readonly ephemeral: EphemeralType; /** * Executable command constructor * @constructor * @param {CommandManager} manager - command manager attached to this command * @param {CommandType} type - command type * @param {FunctionCommandInit} options - command initailization options */ constructor(manager: CommandManager, type: CommandType, options: FunctionCommandInit); /** * Invoke the command * @param {InputManager} input - input data manager * @returns {Promise<void>} A *Promise* that resolves after the function command is completed * @public * @async */ start(input: InputManager): Promise<void>; /** * Reply handler * @param {Message | Interaction} interaction - Discord interaction object * @param {void | string | MessageEmbed | ReplyMessageOptions} result - result of command function execution * @return {Promise<void>} * @private * @async */ private handleReply; }