Annotation Interface SlashCommand


@Retention(RUNTIME) @Target(METHOD) public @interface SlashCommand
Marks a method as a slash command handler. The method must accept a single parameter of type SlashCommandInteractionEvent.

Example:

@SlashCommand(name = "ping", description = "Check bot latency")
public void ping(SlashCommandInteractionEvent event) {
    long ping = event.getJDA().getGatewayPing();
    event.reply("Pong! " + ping + "ms").queue();
}

With Options:

@SlashCommand(
    name = "greet",
    description = "Greet a user",
    options = {
        @CommandOption(name = "user", description = "User to greet", type = OptionType.USER, required = true)
    }
)
public void greet(SlashCommandInteractionEvent event) {
    User user = event.getOption("user").getAsUser();
    event.reply("Hello, " + user.getAsMention() + "!").queue();
}

The core automatically:

  • Registers the command when plugin is enabled
  • Syncs to Discord (globally by default)
  • Unregisters and re-syncs when plugin is disabled
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Returns the description of the slash command.
    Returns the name of the slash command.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Indicates whether the slash command is available globally or restricted to specific guilds.
    long[]
    Returns the IDs of the guilds where this slash command is available.
    net.dv8tion.jda.api.interactions.InteractionContextType[]
    Returns the interaction context types in which this slash command is available.
    net.dv8tion.jda.api.interactions.IntegrationType[]
    Returns the integration types for which this slash command is available.
    boolean
    Indicates whether the slash command is NSFW (Not Safe For Work).
    Returns the command options for this slash command.
    net.dv8tion.jda.api.Permission[]
    Returns the permissions required to execute the slash command.
    Returns the subcommands associated with this slash command.
  • Element Details

    • name

      String name
      Returns the name of the slash command. This name is used to identify and invoke the command in Discord. Command names must be unique within a guild or globally, depending on registration scope.
      Returns:
      the name of the command as a String; Max 32 characters with no backspace
    • description

      String description
      Returns the description of the slash command. This description is displayed to users in the Discord client when they view the command. Command descriptions must be concise and informative, explaining what the command does.
      Returns:
      the description of the command as a String; Max 100 characters
    • nsfw

      boolean nsfw
      Indicates whether the slash command is NSFW (Not Safe For Work). If set to true, the command will only be available in channels marked as NSFW. Defaults to true.
      Returns:
      true if the command is NSFW, false otherwise
      Default:
      true
    • options

      CommandOption[] options
      Returns the command options for this slash command. Command options define the parameters that users can provide when invoking the command. Each option includes a name, description, type, and other constraints such as whether it is required, allowed choices, minimum/maximum values, and support for auto-completion.
      Returns:
      an array of CommandOption annotations defining the command's parameters; defaults to an empty array
      Default:
      {}
    • subcommands

      Subcommand[] subcommands
      Returns the subcommands associated with this slash command. Subcommands allow a single slash command to have multiple related actions, each with their own name, description, and options.
      Returns:
      an array of Subcommand annotations defining the subcommands; defaults to an empty array
      Default:
      {}
    • global

      boolean global
      Indicates whether the slash command is available globally or restricted to specific guilds. If set to true, the command will be registered globally across all guilds. If set to false, the command will only be registered in the guilds specified by guildIds(). Defaults to true.
      Returns:
      true if the command is global, false if it is guild-specific
      Default:
      true
    • guildIds

      long[] guildIds
      Returns the IDs of the guilds where this slash command is available. If the command is guild-specific (i.e., global() returns false), this method specifies the exact guilds in which the command will be registered. If global() returns true, this method has no effect.
      Returns:
      an array of guild IDs as long values; defaults to an empty array
      Default:
      {}
    • permissions

      net.dv8tion.jda.api.Permission[] permissions
      Returns the permissions required to execute the slash command. These permissions define the minimum set of privileges that a user must have in the guild or channel to successfully invoke the command. If the command is global, these permissions apply across all contexts where the command is available. If the command is guild-specific, these permissions are enforced within the specified guilds.
      Returns:
      an array of Permission enums representing the required permissions; defaults to an empty array
      Default:
      {}
    • integrationTo

      net.dv8tion.jda.api.interactions.IntegrationType[] integrationTo
      Returns the integration types for which this slash command is available. Integration types determine how and where the command can be installed and used. By default, the command is integrated as a guild install type.
      Returns:
      an array of IntegrationType enums indicating the supported integration types; defaults to IntegrationType.GUILD_INSTALL
      Default:
      {GUILD_INSTALL}
    • integrationContext

      net.dv8tion.jda.api.interactions.InteractionContextType[] integrationContext
      Returns the interaction context types in which this slash command is available. Interaction contexts define where the command can be used, such as in guilds, direct messages, or other specific environments. This setting helps control the visibility and accessibility of the command based on the user's current context.
      Returns:
      an array of InteractionContextType enums indicating the supported interaction contexts; defaults to InteractionContextType.GUILD
      Default:
      {GUILD}