Skip to content

Examples

Kick Command

import { Command, CommandGuard, CommandInteraction, Commander, CommanderType, Guard } from "@rbxts/commander";
const isAdmin: CommandGuard = (interaction) => {
if (interaction.executor.UserId !== 1) {
interaction.error("Insufficient permission!");
return false;
}
return true;
};
@Commander()
class KickCommand {
@Command({
name: "kick",
description: "Kick a player",
arguments: [
{
name: "player",
description: "Player to kick",
type: CommanderType.Player
}
]
})
@Guard(isAdmin)
kick(interaction: CommandInteraction, player: Player) {
player.Kick("You have been kicked from the server.");
interaction.reply(`Successfully kicked ${player.Name}`);
}
}

Info Command

@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",
},
],
// Global groups are groups assigned to all commands
// defined in this class.
globalGroups: ["info"],
})
class InfoCommand {
// This command will be executable through "info user view" once registered!
@Command({
name: "view",
arguments: [
{
name: "player",
description: "Player to display information about",
type: CommanderType.Player,
},
],
})
@Group("user") // You can also define groups like this: @Group("info", "user")
userView(interaction: CommandInteraction, player: Player) {
interaction.reply(`<Random data about ${player.Name}...>`);
}
// This command can have the same name as the above command, because it
// is grouped under "server" instead.
// This command will be executable through "info server view" once registered!
@Command({
name: "view",
})
@Group("server")
serverView(interaction: CommandInteraction) {
interaction.error("Not implemented!");
}
}