Annotation Interface ContextCommand


@Target(METHOD) @Retention(RUNTIME) public @interface ContextCommand

Methods annotated with ContextMenu will be registered as a context menu command.

Therefore, the method must be declared inside a class that is annotated with Interaction. Furthermore, the method signature has to meet the following conditions:

  • First parameter must be of type CommandEvent
  • Second parameter must either be a User or a Message

Examples:

@ContextCommand(value = "message context command", type = Command.Type.MESSAGE)
public void onCommand(CommandEvent event, Message target) { ... }

@ContextCommand(value = "user context command", type = Command.Type.USER)
public void onCommand(CommandEvent event, User target) { ... }
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    net.dv8tion.jda.api.interactions.commands.Command.Type
    Gets the type of this command.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    net.dv8tion.jda.api.Permission[]
    Returns an array of Permission this command should be enabled for by default.
    boolean
    Returns whether this command is only usable in a guild.
    boolean
    Returns whether this command can only be executed in NSFW channels.
    Returns whether this command should be registered as a global or as a guild command.
    Returns the name of the command.
  • Element Details

    • value

      String value
      Returns the name of the command.
      Returns:
      the name of the command
      Default:
      ""
    • isGuildOnly

      boolean isGuildOnly
      Returns whether this command is only usable in a guild. This only has an effect if this command is registered globally.
      Returns:
      true if this command is only usable in a guild
      Default:
      false
    • isNSFW

      boolean isNSFW
      Returns whether this command can only be executed in NSFW channels.
      Returns:
      true if this command can only be executed in NSFW channels
      Default:
      false
    • enabledFor

      net.dv8tion.jda.api.Permission[] enabledFor
      Returns an array of Permission this command should be enabled for by default. Note that guild admins can modify this at any time.
      Returns:
      an array of permissions this command will be enabled for by default
      See Also:
      • Permission
      • DefaultMemberPermissions.ENABLED
      • DefaultMemberPermissions.DISABLED
      Default:
      {UNKNOWN}
    • scope

      Returns whether this command should be registered as a global or as a guild command.
      Returns:
      whether this command should be registered as a global or as a guild command
      See Also:
      Default:
      GLOBAL
    • type

      net.dv8tion.jda.api.interactions.commands.Command.Type type
      Gets the type of this command.
      Returns:
      the type of the command