Guards
A command guard is simply a function that can be used to determine if a command should be executed.
Guards can be assigned in three ways:
- At the class-level, which assigns the guard to all commands in the class. Guards assigned at the class-level will be executed before method-level guards.
- At the method-level, which assigns the guard to a single command.
- Through the
guards
option when starting Centurion, which assigns the guard to all commands.
A guard function is passed the same CommandContext
that will be passed to the command.
You can use this to access data such as the command path or executor, and you
can send a reply using its reply
and error
methods.
A guard function should return a boolean
- true
if the command should be executed,
false
if not.