Skip to content

Latest commit

 

History

History
133 lines (80 loc) · 4.33 KB

reference.md

File metadata and controls

133 lines (80 loc) · 4.33 KB

Documentation reference

Commands

After you have created your bot, you can start adding commands to it.

To add commands you have to use the bot.addCommand(name, handler, documentation?) method.

For example:

bot.addCommand("ping", () => "pong", {
    description: "Ping the bot",
    explanation: "This command is used to ping the bot in order to check if it is working",
    example: {
        input: "test",
        output: "pong",
    },
});

This method takes three arguments:

name

The name of the command. This is the name that the user will have to type to execute the command.

  • Value type: string
  • required: true

handler

This is a function that will be executed when the user types the command name followed by the bot symbol. The Message and Client types will be specified on the class that implements the bot builder, they extend the BaseMessage and EventEmitter types respectively.

If there is, the returned value will be sent to the user as a message. If not, nothing will be sent.

  • Value type: (message?: Message, client?: Client) => string | number | void
  • required: true

documentation

The documentation of the command. This is an object that contains information about the command.

Types

Message

The Message type is a generic type that extends the BaseMessage (and implement the reply method). It could have many properties depending on the implementation of the bot builder, but due to this library command's processing, it will at least have the following properties:

command

The name of the command that was executed.

  • Value type: string

text

The text that the user typed after the command name.

  • Value type: string

args

The array containing every word that the user typed after the command name.

  • Value type: string[]

reply

The function that the bot will use to reply to the user.

  • Value type: reply: (...args) => Promise<any>

Client

The Client type is a generic type that extends the EventEmitter.

Documentation

The Documentation type is an object that contains information about the command.

description

Short description of the command. It will be listed on the general help command. If there isn't a description, it will just list the name without any description.

For example, the ping command's description is: Ping the bot

general help message

  • Value type: string

explanation

Longer explanation of the command. It will be listed on the specific help command. If there isn't an explanation, the description will be sent instead; if there isn't documentation at all, it will reply This command has no documentation.

For example, the ping command's explanation is: This command is used to ping the bot in order to check if it is working

specific command help message

  • Value type: string

example

An example of the command usage. It will be listed on the specific help command. If there isn't an example, nothing will be sent.

Both the input and the output are optional.

In this case, the input is empty, and the output is pong.

example without input

In this one, the input is test, and the output is still pong.

example with input and output

Last, but not least, in this case, the input is test, and the output is empty.

example without output

  • Value type: Object
    • input: string
    • output: string