Annotation Interface ContextMenu
Context menus appear when right-clicking on users or messages in Discord.
The method will be called with either a UserContextInteractionEvent
or MessageContextInteractionEvent.
User Context Menu Example:
@ContextMenu(name = "Get User Info", type = Command.Type.USER)
public void getUserInfo(UserContextInteractionEvent event) {
User target = event.getTarget();
event.reply("User: " + target.getAsTag() + "\nID: " + target.getId()).queue();
}
Message Context Menu Example:
@ContextMenu(name = "Bookmark Message", type = Command.Type.MESSAGE)
public void bookmarkMessage(MessageContextInteractionEvent event) {
Message message = event.getTarget();
// Save bookmark...
event.reply("Message bookmarked!").setEphemeral(true).queue();
}
With Permissions, IntegrationType & InteractionContextType:
@ContextMenu(
name = "Ban User",
type = Command.Type.USER,
permissions = {Permission.BAN_MEMBERS},
integrationTo = {IntegrationType.GUILD_INSTALL},
integrationContext = {InteractionContextType.GUILD}
)
public void banUser(UserContextInteractionEvent event) {
// only members with BAN_MEMBERS can see/use this menu in guilds
}
The core automatically:
- Registers the command when plugin is enabled
- Applies default member permissions, integration types and interaction contexts
- Syncs to Discord (globally by default)
- Unregisters and re-syncs when plugin is disabled
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanIndicates whether this context menu should be registered globally or per-guild.long[]Returns an array of guild IDs where this context menu should be registered.net.dv8tion.jda.api.interactions.InteractionContextType[]Returns the interaction context types in which this context menu is available.net.dv8tion.jda.api.interactions.IntegrationType[]Returns the integration types for which this context menu is available.booleanIndicates whether the context menu is NSFW (Not Safe For Work).net.dv8tion.jda.api.Permission[]Returns the default member permissions required to see and use this context menu.
-
Element Details
-
baseName
String baseNameReturns the base name of the context menu. This name is in format of 'baseName > funcName' to charity mixed plugin may had mismatch display name.- Returns:
- the base name of the context menu (the format result must not excess 32 characters)
-
funcName
String funcNameReturns the function name of the context menu. This name is in format of 'baseName > funcName' to charity mixed plugin may had mismatch display name.- Returns:
- the function name of the context menu (the format result must not excess 32 characters)
-
type
net.dv8tion.jda.api.interactions.commands.Command.Type typeReturns the type of context menu this command represents.The type determines whether the context menu appears when right-clicking on a user or a message. For user context menus, the handler receives a
UserContextInteractionEvent. For message context menus, the handler receives aMessageContextInteractionEvent.- Returns:
- the context menu type (USER or MESSAGE)
-
global
boolean globalIndicates whether this context menu should be registered globally or per-guild.When
true, the context menu will be available across all guilds the bot is in. Whenfalse, the context menu must be explicitly registered per guild usingguildIds().- Returns:
trueif the context menu should be registered globally,falseotherwise; Defaulttrue
- Default:
true
-
guildIds
long[] guildIdsReturns an array of guild IDs where this context menu should be registered.This method is used when
global()is set tofalseto specify the exact guilds where the context menu should appear. Ifglobal()istrue, this setting has no effect and the context menu will be registered globally across all guilds.- Returns:
- an array of guild IDs, or an empty array if not specified or if global registration is enabled
- Default:
{}
-
nsfw
boolean nsfwIndicates whether the context menu is NSFW (Not Safe For Work). If set to true, the menu will only be available in channels marked as NSFW. Defaults totrue.- Returns:
trueif the context menu is NSFW,falseotherwise
- Default:
true
-
permissions
net.dv8tion.jda.api.Permission[] permissionsReturns the default member permissions required to see and use this context menu.These permissions define the minimum set of privileges that a member must have in the guild to have this context menu visible and executable. Discord enforces these as default member permissions — members lacking them will not see the menu in their client.
If no permissions are specified, the context menu is available to every member who can normally use it in the given
integrationContext().- 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 context menu is available. Integration types determine how and where the command can be installed and used. By default, the context menu 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 context menu is available. Interaction contexts define where the command can be used, such as in guilds, direct messages, or other specific environments. This setting controls the visibility and accessibility of the menu based on the user's current context.- Returns:
- an array of
InteractionContextTypeenums indicating the supported interaction contexts; defaults toInteractionContextType.GUILD
- Default:
{GUILD}
-