Annotation Interface SlashCommand


@Target(METHOD) @Retention(RUNTIME) public @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

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Returns the description of the command.
    Returns an array of Permissions 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

      String value
      Returns the name of the command.
      Returns:
      the name of the command
      Default:
      ""
    • isGuildOnly

      boolean isGuildOnly
      Returns 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 desc
      Returns the description of the command.
      Returns:
      the description of the command
      Default:
      "N/A"
    • isNSFW

      boolean isNSFW
      Returns 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[] enabledFor
      Returns an array of Permissions 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

      Returns 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