UNPKG

commandbot

Version:

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

143 lines (142 loc) 4.34 kB
/// <reference types="node" /> import { Client, ClientOptions, CommandInteraction, Message } from "discord.js"; import { EventEmitter } from "events"; import { CommandManager } from "./CommandManager.js"; import { SystemMessageManager } from "./SystemMessage.js"; import { InputManager } from "./InputManager.js"; import { HelpMessageParams } from "../commands/Help.js"; /** * Main object initialization options * @interface */ export interface InitOptions { /** * Bot name * @type {string} */ name: string; /** * Prefix used as a way to trigger the bot using messages in all guilds by default * @remarks * If *undefined*, you can only interact with bot using slash commands or context menus * @type {?string} */ globalPrefix?: string; /** * Separator used to split user input to a list of {@link InputParameter}s (applies to prefix interactions) * @type {?string} */ argumentSeparator?: string; /** * Separator used to split subcommands when using prefix interactions * @type {?string} */ commandSeparator?: string; /** * Additional [ClientOptions](https://discord.js.org/#/docs/main/stable/typedef/ClientOptions) for Discord.js [Client](https://discord.js.org/#/docs/main/stable/class/Client) object * @type {?ClientOptions} */ clientOptions?: ClientOptions; /** * Help message appearance configuration * @type {?HelpMessageParams} */ help?: HelpMessageParams; /** * Discord bot token * @type {string} */ token: string; /** * Discord API application ID * @type {string} */ applicationId: string; } export declare interface Bot { /** * Emitted after connecting to Discord API * @event */ on(event: "READY", listener: Function): this; /** * Emitted whenever bot receives a Discord message * @event */ on(event: "MESSAGE", listener: (m: Message) => void): this; /** * Emitted whenever bots receives a Discord message or interaction that gets recognized as a CommandBot command * @event */ on(event: "COMMAND", listener: (m: Message | CommandInteraction, cmdMsg: InputManager) => void): this; /** * Emitted on every bot error * @event */ on(event: "ERROR", listener: (e: any) => void): this; } /** * Application instance * @class * @extends {EventEmitter} */ export declare class Bot extends EventEmitter { /** * Bot name * @type {string} * @public * @readonly */ readonly name: string; /** * Discord.js {@link Client} instance * @type {Client} * @public * @readonly */ readonly client: Client; /** * Instance command manager * @type {CommandManager} * @public * @readonly */ readonly commands: CommandManager; /** * Discord Bot token * @type {string} * @public * @readonly */ readonly token: string; /** * Discord API application ID * @type {string} * @public * @readonly */ readonly applicationId: string; /** * {@link SystemMessageManager} storing messages' configuration * @type {SystemMessageManager} * @public * @readonly */ readonly messages: SystemMessageManager; /** * Main bot constructor * @constructor * @param {InitOptions} options - instance properties ({@link InitOptions}) */ constructor({ name, token, applicationId, globalPrefix, argumentSeparator, commandSeparator, clientOptions, help }: InitOptions); /** * Starts your Discord bot * @param {?number} [port] - if specified, the app will create a http server that will be listening on the specified port (useful when hosting your bot on platforms like Heroku) * @param {?boolean} [register=true] - if *true* or *undefined*, the bot will register all interactions in the Discord API * @returns {Promise<boolean>} whether this operation has been completed successfully * @public * @async */ start(port?: number, register?: boolean): Promise<boolean>; } export default Bot;