Aliases this command can be called by
The specification for this command's arguments. This determines how arguments will be parsed when the command is triggered
Middleware cache for this command. To add a middleware function, see
MiddlewareCache#use()
The name this command can be called by. In the event that a command is marked as regex-only or trigger-only this will strictly be used as an identifier for the command in the cache
Regular expression that triggers this command. Command regular expressions are run against the unmodified message content so they are not subject to prefix restrictions. If a message uses a prefix and that message does not match the regex, the command will not be run (unless the message would otherwise call the command by name and the command is not set to regex-only)
NOTE: The first command with a regular expression that matches the input will be run. The order in which the command regex are checked should be the order in which the commands are added to the cache. If you use regex in multiple commands, you should ensure that they do not have overlapping logic such that no two regular expressions should match for the same message. Otherwise you will have a command that will never run from its regex.
Whether or not this command will ignore messages that would otherwise call it by name/alias and thus rely solely on triggering by regular expression
Whether or not this command will ignore messages that would otherwise call it by name/alias and thus rely solely on the result of the trigger function for whether or not this command will run
Commands must implement an action method which will be executed when the
command is called via Discord. The action method will be given a
CommandContext
object when called
Commands may implement an init()
method that can be used to set up any
resources the command may need to utilize at runtime. The init method will
be called after the client is ready and will be passed the client instance
for use if needed.
NOTE: All command init methods will be run simultaneously through
Promise.all()
so race conditions are possible if you have commands
relying on similar resources
Commands may implement an onError()
method that will be called when there
is an error parsing or resolving arguments, an error from a middleware function,
or an uncaught error in the Command's action()
method. This method will
receive an error object and a CommandContext
object. This method must
return Result.ok()
to signify that the error was handled.
If there is an error processing the given error, you should return it as
an Error Result with Result.error()
Commands may implement a trigger()
method that triggers this command if it
returns true. This function should strip whatever triggers it from
MessageContext#content
so that the remainder
can be used as arguments if arguments are desired, otherwise the entierty
of the remaining content (after being potentially modified by rules) will
be parsed as arguments.
The trigger
method will receive a MessageContext
object when called.
Commands triggered in this way are not subject to prefix restrictions from
prefix related rules unless you specifically check MessageContext#prefixUsed
or check for other forms of prefixes in your
trigger logic. Because you have access to both the MessageContext#content
and the original (unmodified) Message
content,
you can choose to rely on prefix mechanics (like relying on the already modified
context content and prefixUsed
) or ignore them entirely (for example if you
wanted to have a command triggered by natural language rather than traditional
command names/aliases).
NOTE: The first command with a trigger that returns true will be run. The order in which the command triggers are checked should be the order in which the commands are added to the cache. If you use triggers in multiple commands, you should ensure that their trigger conditions do not have overlapping logic such that no two triggers should return true for the same message. Otherwise you will have a command that will never run from its trigger.
Generated using TypeDoc
The base Command class you will extend when creating Commands for your Discord Client