UNPKG

commandbot

Version:

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

151 lines (150 loc) 4.64 kB
import { ColorResolvable, DMChannel, GuildMember, Interaction, Message, MessageEmbed, TextChannel, User } from "discord.js"; import { FunctionCommand } from "../commands/base/FunctionCommand.js"; import { PermissionsError } from "../errors.js"; import Bot from "./Bot.js"; /** * Types of system messages * @type */ export declare type MessageType = "PERMISSION" | "ERROR" | "NOT_FOUND" | "SUCCESS"; /** * Configuration of a system message * @interface */ export interface SystemMessageAppearance { /** * Whether this type of message is enabled * @type {boolean} */ enabled: boolean; /** * Title field * @type {string} */ title: string; /** * Text below the title * @type {?string} * @deprecated */ bottomText?: string; /** * Text below the title * @type {?string} */ description?: string; /** * Color of a message * @type {?ColorResolvable} */ accentColor?: ColorResolvable; /** * Whether to display detailed informations in the message * @type {?boolean} */ displayDetails?: boolean; /** * Whether to show current time and date in a footer * @type {?boolean} */ showTimestamp?: boolean; /** * Footer text * @type {?string} * @deprecated */ footer?: string; /** * Time (in ms) after a message of this type gets deleted * @type {?number} * @remarks Set to *Infinity* to not delete the message */ deleteTimeout?: number; } /** * System message data definition * @interface */ export interface SystemMessageData { /** * A {@link Command} instance * @type {?FunctionCommand} */ command?: FunctionCommand; /** * Phrase received from a Discord channel * @type {?string} */ phrase?: string; /** * User who used the bot * @type {?GuildMember | User} */ user?: GuildMember | User; /** * Error object * @type {?Error | PermissionsError | string} */ error?: Error | PermissionsError | string; } /** * Stores configuration and generates system messages * * System messages - predefined messages sent by the bot in special cases (for example after an error, or when a command doesn't exist) * * @remarks You can't customize messages after starting the bot. Changing these properties while the bot is running will have no effect. * * @class */ export declare class SystemMessageManager { /** * Client parent attached to this manager * @type {Bot} * @public * @readonly */ readonly client: Bot; /** * Sent whenever caller's permissions are not sufficient to run a command * @type {SystemMessageAppearance} * @public */ PERMISSION: SystemMessageAppearance; /** * Sent when an error occurs during the execution of a command * @type {SystemMessageAppearance} * @public */ ERROR: SystemMessageAppearance; /** * Sent when someone tries to run a command that does not exist (mainly by using prefix interactions) * @type {SystemMessageAppearance} * @public */ NOT_FOUND: SystemMessageAppearance; /** * Sent when a command function returns _void_ without throwing an error * @type {SystemMessageAppearance} * @public * @remarks An _announceSuccess_ property must be set to _true_ (default) in order to send this message */ SUCCESS: SystemMessageAppearance; /** * Global time (in ms) after a message gets deleted * @type {number} * @public * @remarks This time applies to all message types but it can be overwritten using local properties with the same name (for example ERROR.deleteTimeout) */ deleteTimeout: number; constructor(client: Bot); /** * Generates and sends a system message * @param {MessageType} type - "ERROR" | "PERMISSION" | "NOT_FOUND" | "SUCCESS" * @param {?SystemMessageData} [data] - additional data to include in the message * @param {?Message | Interaction | TextChannel | DMChannel} [interaction] - if specified, the generated message will be sent in this channel * @returns {Promise<MessageEmbed | Message | void>} A message that got sent or *void* * @public * @async */ send(type: MessageType, data?: SystemMessageData, interaction?: Message | Interaction | TextChannel | DMChannel): Promise<MessageEmbed | Message | void>; }