Defining commands
Commands are defined using decorators.
Centurion has four decorators:
@Register
- Classes containing commands must be decorated with this to be registered. You can also register groups from here.@Command
- Used to define commands@Group
- Used to assign groups to a command@Guard
- Used to assign guards to a command
A command can be defined like so:
Command context
Each command is passed a CommandContext
as its first argument.
The primary purpose of a CommandContext
is to send a response back
to the command executor.
It also contains data such as the command executor and the text used to execute the command.
Type safety
Type safety can only be provided if the types for your arguments match your parameters’ types.
It’s worth keeping in mind that no warning or error will be displayed for argument and parameter types that do not match.
To avoid confusing bugs or errors, you should exercise caution when defining command arguments and ensure they have the correct type.
For example, the following code would not be type-safe - the argument types and parameter types don’t match!
In order to assert that the argument and parameter types are equal, we would need a way to retrieve each parameter’s type. Unfortunately, this is not possible without using a TypeScript transformer. There are no plans to implement this currently, as it would require manual configuration and add a significant maintenance cost to the project.