Annotation Interface ContextMenu


@Retention(RUNTIME) @Target(METHOD) public @interface ContextMenu
Marks a method as a context menu handler.

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
    Modifier and Type
    Required Element
    Description
    Returns the base name of the context menu.
    Returns the function name of the context menu.
    net.dv8tion.jda.api.interactions.commands.Command.Type
    Returns the type of context menu this command represents.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Indicates 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.
    boolean
    Indicates 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 baseName
      Returns 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 funcName
      Returns 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 type
      Returns 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 a MessageContextInteractionEvent.

      Returns:
      the context menu type (USER or MESSAGE)
    • global

      boolean global
      Indicates 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. When false, the context menu must be explicitly registered per guild using guildIds().

      Returns:
      true if the context menu should be registered globally, false otherwise; Default true
      Default:
      true
    • guildIds

      long[] guildIds
      Returns an array of guild IDs where this context menu should be registered.

      This method is used when global() is set to false to specify the exact guilds where the context menu should appear. If global() is true, 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 nsfw
      Indicates 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 to true.
      Returns:
      true if the context menu is NSFW, false otherwise
      Default:
      true
    • permissions

      net.dv8tion.jda.api.Permission[] permissions
      Returns 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 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 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 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 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 InteractionContextType enums indicating the supported interaction contexts; defaults to InteractionContextType.GUILD
      Default:
      {GUILD}