Annotation Interface SlashCommand
Methods annotated with SlashCommand will be registered as a slash command at startup.
Therefore, the method must be declared inside a class that is annotated with Interaction
.
Furthermore, the method signature has to meet the following conditions:
- First parameter must be of type
CommandEvent
- Remaining parameter types must be registered at the
TypeAdapters
- or the second parameter is a String array
Examples:
@SlashCommand("greet")
public void onCommand(CommandEvent event) {
event.reply("Hello World!");
}
@SlashCommand(value="moderation ban", desc="Bans a member", enabledFor=Permission.BAN_MEMBERS)
public void onCommand(CommandEvent event, @Param("The member to ban") Member target, @Optional("no reason given") String reason) { ... }
@SlashCommand(value = "favourite fruit")
public void onCommand(CommandEvent event, @Choices({"Apple", "Banana", "Orange"}) String fruit) {
event.reply("You've chosen: %s", fruit);
}
@SlashCommand("example command") {
public void onCommand(CommandEvent event, String[] arguments) {}
}
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionReturns the description of the command.Returns an array ofPermission
s this command should be enabled for by default.boolean
Returns whether this command is only usable in a guild.boolean
Returns whether this command can only be executed in NSFW channels.Returns whether this command should be registered as a global or as a guild command.Returns the name of the command.
-
Element Details
-
value
-
isGuildOnly
boolean isGuildOnlyReturns whether this command is only usable in a guild. This only has an effect if this command is registered globally.- Returns:
true
if this command is only usable in a guild
- Default:
false
-
desc
String descReturns the description of the command.- Returns:
- the description of the command
- Default:
"N/A"
-
isNSFW
boolean isNSFWReturns whether this command can only be executed in NSFW channels.- Returns:
true
if this command can only be executed in NSFW channels
- Default:
false
-
enabledFor
Permission[] enabledForReturns an array ofPermission
s this command should be enabled for by default. Note that guild admins can modify this at any time.- Returns:
- an array of permissions this command will be enabled for by default
- See Also:
- Default:
{UNKNOWN}
-
scope
CommandScope scopeReturns whether this command should be registered as a global or as a guild command.- Returns:
- whether this command should be registered as a global or as a guild command
- See Also:
- Default:
GLOBAL
-