Annotation 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 ElementsModifier and TypeRequired ElementDescriptionReturns the description of the slash command.Returns the name of the slash command. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanIndicates 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.booleanIndicates 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 nameReturns 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 descriptionReturns 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 nsfwIndicates 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 totrue.- Returns:
trueif the command is NSFW,falseotherwise
- Default:
true
-
options
CommandOption[] optionsReturns 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
CommandOptionannotations defining the command's parameters; defaults to an empty array
- Default:
{}
-
subcommands
Subcommand[] subcommandsReturns 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
Subcommandannotations defining the subcommands; defaults to an empty array
- Default:
{}
-
global
boolean globalIndicates whether the slash command is available globally or restricted to specific guilds. If set totrue, the command will be registered globally across all guilds. If set tofalse, the command will only be registered in the guilds specified byguildIds(). Defaults totrue.- Returns:
trueif the command is global,falseif it is guild-specific
- Default:
true
-
guildIds
long[] guildIdsReturns the IDs of the guilds where this slash command is available. If the command is guild-specific (i.e.,global()returnsfalse), this method specifies the exact guilds in which the command will be registered. Ifglobal()returnstrue, 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[] permissionsReturns 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
Permissionenums representing the required permissions; defaults to an empty array
- Default:
{}
-
integrationTo
net.dv8tion.jda.api.interactions.IntegrationType[] integrationToReturns 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
IntegrationTypeenums indicating the supported integration types; defaults toIntegrationType.GUILD_INSTALL
- Default:
{GUILD_INSTALL}
-
integrationContext
net.dv8tion.jda.api.interactions.InteractionContextType[] integrationContextReturns 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
InteractionContextTypeenums indicating the supported interaction contexts; defaults toInteractionContextType.GUILD
- Default:
{GUILD}
-