CommandListener

CommandListener

Class representing a bot Command. Commands can be used to respond to user messages or act on certain trigger phrases being mentioned but differ from Listeners in that they require the bot to be directly mentioned. Commands can make use of regular methods, or Responders

Constructor

new CommandListener(options)

Create a bot command.
Source:
Parameters:
Name Type Description
options Object The command options. See Listener.
Examples

Create and register a command using a responder

bot.use(new Bot.Listener.Command({
    name: 'dice roller',
    trigger: 'roll a die',
    handler: new Bot.Responder.RandomMessage({
        messages: [
            '1', '2', '3', '4', '5', '6'
        ]
    })
}));

Create and register a command using a handler function

bot.use(new Bot.Listener.Command({
    name: 'meaning of life',
    trigger: /what('?s| is) the meaning of life/i,
    handler: async message => {
        await bot.replyTo(message).with('42');
    }
}));

Extends

Methods

(static) create() → {CommandListener}

Create a bot command (see CommandListener for parameters).
Source:
Returns:
Type:
CommandListener
The new command.