Skip to content

Guards

A command guard is simply a function that can be used to determine if a command should be executed. You can use the @Guard decorator to assign guards to a command.

A guard function is passed the same CommandInteraction 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.

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}`);
}
}