Class UserContextMenu


public abstract class UserContextMenu extends ContextMenu

User Context Menus In JDA-Chewtils

The internal inheritance for User Context Menus used in JDA-Chewtils is that of the object.

Classes created inheriting this class gain the unique traits of commands operated using the menu Extension.
Using several fields, a menu can define properties that make it unique and complex while maintaining a low level of development.
All classes extending this class can define any number of these fields in a object constructor and then create the menu action/response in the abstract execute(UserContextMenuEvent) body:

 public class ExampleCmd extends UserContextMenu {

      public ExampleCmd() {
          this.name = "Example";
      }

      @Override
      protected void execute(UserContextMenu event) {
          event.reply("Hey look! This would be the bot's reply if this was a command!");
      }

 }
Execution is with the provision of a UserContextInteractionEvent-CommandClient wrapper called a UserContextMenuEvent and is performed in two steps:
  • run - The menu runs through a series of conditionals, automatically terminating the command instance if one is not met, and possibly providing an error response.
  • execute - The menu, now being cleared to run, executes and performs whatever lies in the abstract body method.
Author:
Olivia (Chew)
  • Constructor Details

    • UserContextMenu

      public UserContextMenu()
  • Method Details

    • run

      public final void run(UserContextMenuEvent event)
      Runs checks for the UserContextMenu with the given MessageContextMenuEvent that called it.
      Will terminate, and possibly respond with a failure message, if any checks fail.
      Parameters:
      event - The UserContextMenuEvent that triggered this Context Menu
    • execute

      protected abstract void execute(UserContextMenuEvent event)
      The main body method of a UserContextMenu.
      This is the "response" for a successful run(UserContextMenuEvent)
      Parameters:
      event - The UserContextMenuEvent that triggered this menu.
    • buildCommandData

      public net.dv8tion.jda.api.interactions.commands.build.CommandData buildCommandData()
      Description copied from class: ContextMenu
      Builds CommandData for the ContextMenu upsert. This code is executed when we need to upsert the menu. Useful for manual upserting.
      Overrides:
      buildCommandData in class ContextMenu
      Returns:
      the built command data