Skip to content

Groups

Groups are a way to organize your commands, effectively turning them into subcommands.

Groups must be defined in the @Commander decorator in order to be used. You can use the @Group decorator to assign a command to a group.

For example, let’s say you want to organize view and delete commands under a profile group:

@Commander({
groups: [
{
name: "profile",
description: "Profile commands",
},
],
})
class ProfileCommand {
@Command({
name: "view",
description: "Views a player's profile",
arguments: [
{
name: "player",
description: "The player",
type: CommanderType.Player,
},
],
})
@Group("profile")
view(interaction: CommandInteraction, player: Player) {}
@Command({
name: "delete",
description: "Deletes a player's profile",
arguments: [
{
name: "player",
description: "The player",
type: CommanderType.Player,
},
],
})
@Group("profile")
delete(interaction: CommandInteraction, 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:

@Commander({
groups: [
{
name: "info",
description: "View info about a user or the server",
},
{
name: "user",
description: "View info about a user",
root: "info",
},
{
name: "server",
description: "View info about the server",
root: "info",
},
],
})
class InfoCommand {
@Command({
name: "view",
description: "View information about a player",
arguments: [{ name: "player", description: "Player to view information for", type: CommanderType.Player }],
})
// If info was a global group, you could do @Group("user") here
@Group("info", "user")
userView(interaction: CommandInteraction, player: Player) {}
@Command({
name: "view",
description: "View information about the server",
})
@Group("info", "server")
serverView(interaction: CommandInteraction, player: Player) {}
}