Groups
Groups are a way to organize your commands, effectively turning them into subcommands.
To assign groups, you need to register them first. You can do this from the @Register decorator or registerGroup.
You can then use the @Group
decorator to assign a command to a group.
You can assign groups in two ways:
- At the class-level, which assigns the group to all commands in the class.
- At the method-level, which assigns the group to a single command.
For example, let’s say you want to organize view and delete commands under a profile group:
@Register()// Assigning a group at the class level assigns the group to all// commands in the class.// You can also do this at the method level, but it's recommended to do it this// way if all commands have the same group to reduce repetition.@Group("profile")class ProfileCommand {@Command({ name: "view", description: "Views a player's profile", arguments: [ { name: "player", description: "The player", type: CenturionType.Player, }, ],})view(ctx: CommandContext, player: Player) {}
@Command({ name: "delete", description: "Deletes a player's profile", arguments: [ { name: "player", description: "The player", type: CenturionType.Player, }, ],})delete(ctx: CommandContext, player: Player) {}}
Nested groups
Groups at the top level can have child group(s), whereas groups that have a parent cannot have child groups. This limitation means the maximum nesting level is 2, as of now.
To define a group as a child of another group, you specify its name using the root key:
@Register()@Group("info")class InfoCommand {@Command({ name: "view", description: "View information about a player", arguments: [{ name: "player", description: "Player to view information for", type: CenturionType.Player }],})// If info was a global group, you could do @Group("user") here@Group("user")userView(ctx: CommandContext, player: Player) {}
@Command({ name: "view", description: "View information about the server",})@Group("server")serverView(ctx: CommandContext, player: Player) {}}