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();
}
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 -
Optional Element Summary
Optional Elements
-
Element Details
-
name
String nameReturns the display name of the context menu. This name is shown to users in the Discord client when they right-click on a user or message.- Returns:
- the name of the context menu (Max 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:
{}
-