import HandlesClient from '../core/Client'; import { IConfig } from '../interfaces/Config'; import Response, { TextBasedChannel } from './Response'; import { Client, Guild, GuildMember, Message, User } from 'discord.js'; export declare type Trigger = string | RegExp; export interface ICommandOptions { trigger: Trigger; message: Message; body: string; } /** * A command. * ```js * const { Command } = require('discord-handles'); * module.exports = class extends Command { * static get triggers() { * return ['ping', 'pung', 'poing', 'pong']; * } * * exec() { * return this.response.success(`${this.trigger} ${Date.now() - this.message.createdTimestamp}ms`); * } * }; */ export default class Command { static triggers?: Trigger | Trigger[]; /** * The handles client. */ readonly handles: HandlesClient; /** * The command trigger that caused the message to run this command. */ readonly trigger: Trigger; /** * The message that triggered this command. */ readonly message: Message; /** * The body of the command (without prefix or command), as provided in the original message. */ body: string; /** * Client config. */ config: IConfig; /** * The command arguments as set by arguments in executor. */ args?: any; /** * The response object for this command. */ response: Response; constructor(client: HandlesClient, {trigger, message, body}: ICommandOptions); /** * The Discord.js client. */ readonly client: Client; /** * The guild this command is in. */ readonly guild: Guild; /** * The channel this command is in. */ readonly channel: TextBasedChannel; /** * The author of this command. */ readonly author: User; readonly member: GuildMember; /** * Ensure unique commands for an author in a channel. * Format: "authorID:channelID" */ readonly session: string; /** * Executed prior to {@link Command#exec}. Should be used for middleware/validation. * ```js * async pre() { * await new handles.Argument(this, 'someArgument') * .setResolver(c => c === 'dank memes' ? 'top kek' : null); * } */ pre(): void; /** * The command execution method */ exec(): void; /** * Executed after {@link Command#exec}. Can be used for responses. */ post(): void; /** * Executed when any of the command execution methods error. Any errors here will be discarded. */ error(): void; }