Interface CommandListener


public interface CommandListener
An implementable "Listener" that can be added to a CommandClient and used to handle events relating to Commands.
Author:
John Grosh (jagrosh)
  • Method Details

    • onCommand

      default void onCommand(CommandEvent event, Command command)
      Called when a Command is triggered by a CommandEvent.
      Parameters:
      event - The CommandEvent that triggered the Command
      command - The Command that was triggered
    • onSlashCommand

      default void onSlashCommand(SlashCommandEvent event, SlashCommand command)
      Called when a SlashCommand is triggered by a SlashCommandEvent.
      Parameters:
      event - The SlashCommandEvent that triggered the Command
      command - The SlashCommand that was triggered
    • onMessageContextMenu

      default void onMessageContextMenu(MessageContextMenuEvent event, MessageContextMenu menu)
      Called when a MessageContextMenu is triggered by a MessageContextMenuEvent.
      Parameters:
      event - The MessageContextMenuEvent that triggered the MessageContextMenu
      menu - The MessageContextMenu that was triggered
    • onUserContextMenu

      default void onUserContextMenu(UserContextMenuEvent event, UserContextMenu menu)
      Called when a UserContextMenu is triggered by a UserContextMenuEvent.
      Parameters:
      event - The UserContextMenuEvent that triggered the UserContextMenu
      menu - The UserContextMenu that was triggered
    • onCompletedCommand

      default void onCompletedCommand(CommandEvent event, Command command)
      Called when a Command is triggered by a CommandEvent after it's completed successfully.

      Note that a successfully completed command is one that has not encountered an error or exception. Calls that do face errors should be handled by CommandListener#onCommandException

      Parameters:
      event - The CommandEvent that triggered the Command
      command - The Command that was triggered
    • onCompletedSlashCommand

      default void onCompletedSlashCommand(SlashCommandEvent event, SlashCommand command)
      Called when a SlashCommand is triggered by a SlashCommandEvent after it's completed successfully.

      Note that a successfully completed slash command is one that has not encountered an error or exception. Calls that do face errors should be handled by CommandListener#onSlashCommandException

      Parameters:
      event - The SlashCommandEvent that triggered the Command
      command - The SlashCommand that was triggered
    • onCompletedMessageContextMenu

      default void onCompletedMessageContextMenu(MessageContextMenuEvent event, MessageContextMenu menu)
      Called when a MessageContextMenu is triggered by a MessageContextMenuEvent after it's completed successfully.

      Note that a successfully completed context menu interaction is one that has not encountered an error or exception. Calls that do face errors should be handled by onTerminatedMessageContextMenu(MessageContextMenuEvent, MessageContextMenu)

      Parameters:
      event - The MessageContextMenuEvent that triggered the Menu
      menu - The MessageContextMenu that was triggered
    • onCompletedUserContextMenu

      default void onCompletedUserContextMenu(UserContextMenuEvent event, UserContextMenu menu)
      Called when a UserContextMenu is triggered by a UserContextMenuEvent after it's completed successfully.

      Note that a successfully completed context menu interaction is one that has not encountered an error or exception. Calls that do face errors should be handled by onTerminatedUserContextMenu(UserContextMenuEvent, UserContextMenu)

      Parameters:
      event - The MessageContextMenuEvent that triggered the Menu
      menu - The MessageContextMenu that was triggered
    • onTerminatedCommand

      default void onTerminatedCommand(CommandEvent event, Command command)
      Called when a Command is triggered by a CommandEvent but is terminated before completion.
      Parameters:
      event - The CommandEvent that triggered the Command
      command - The Command that was triggered
    • onTerminatedSlashCommand

      default void onTerminatedSlashCommand(SlashCommandEvent event, SlashCommand command)
      Called when a SlashCommand is triggered by a SlashCommandEvent but is terminated before completion.
      Parameters:
      event - The SlashCommandEvent that triggered the Command
      command - The SlashCommand that was triggered
    • onTerminatedMessageContextMenu

      default void onTerminatedMessageContextMenu(MessageContextMenuEvent event, MessageContextMenu menu)
      Called when a MessageContextMenu is triggered by a MessageContextMenuEvent but is terminated before completion.
      Parameters:
      event - The ContextMenuEvent that triggered the Context Menu
      menu - The ContextMenu that was triggered
    • onTerminatedUserContextMenu

      default void onTerminatedUserContextMenu(UserContextMenuEvent event, UserContextMenu menu)
      Called when a UserContextMenu is triggered by a UserContextMenuEvent but is terminated before completion.
      Parameters:
      event - The ContextMenuEvent that triggered the Context Menu
      menu - The ContextMenu that was triggered
    • onNonCommandMessage

      default void onNonCommandMessage(net.dv8tion.jda.api.events.message.MessageReceivedEvent event)
      Called when a MessageReceivedEvent is caught by the Client Listener's but doesn't correspond to a Command.

      In other words, this catches all non-command MessageReceivedEvents allowing you to handle them without implementation of another listener.

      Parameters:
      event - A MessageReceivedEvent that wasn't used to call a Command
    • onCommandException

      default void onCommandException(CommandEvent event, Command command, Throwable throwable)
      Called when a Command catches a Throwable during execution.

      This doesn't account for exceptions thrown during other pre-checks, and should not be treated as such!

      An example of this misconception is via a Command.Category test:

       public class BadCommand extends Command {
      
            public BadCommand() {
                this.name = "bad";
                this.category = new Category("bad category", event -> {
                    // This will throw a NullPointerException if it's not from a Guild!
                    return event.getGuild().getIdLong() == 12345678910111213;
                });
            }
      
            @Override
            protected void execute(CommandEvent) {
                event.reply("This is a bad command!");
            }
      
       }

      The NullPointerException thrown will not be caught by this method!

      Parameters:
      event - The CommandEvent that triggered the Command
      command - The Command that was triggered
      throwable - The Throwable thrown during Command execution
    • onSlashCommandException

      default void onSlashCommandException(SlashCommandEvent event, SlashCommand command, Throwable throwable)
      Called when a SlashCommand catches a Throwable during execution.

      This doesn't account for exceptions thrown during other pre-checks, and should not be treated as such!

      The NullPointerException thrown will not be caught by this method!

      Parameters:
      event - The CommandEvent that triggered the Command
      command - The Command that was triggered
      throwable - The Throwable thrown during Command execution
    • onMessageContextMenuException

      default void onMessageContextMenuException(MessageContextMenuEvent event, MessageContextMenu menu, Throwable throwable)
      Called when a ContextMenu catches a Throwable during execution.

      This doesn't account for exceptions thrown during other pre-checks, and should not be treated as such!

      The NullPointerException thrown will not be caught by this method!

      Parameters:
      event - The Context Menu Event that triggered the ContextMenu
      menu - The Context Menu that was triggered
      throwable - The Throwable thrown during Command execution
    • onUserContextMenuException

      default void onUserContextMenuException(UserContextMenuEvent event, UserContextMenu menu, Throwable throwable)
      Called when a ContextMenu catches a Throwable during execution.

      This doesn't account for exceptions thrown during other pre-checks, and should not be treated as such!

      The NullPointerException thrown will not be caught by this method!

      Parameters:
      event - The Context Menu Event that triggered the ContextMenu
      menu - The Context Menu that was triggered
      throwable - The Throwable thrown during Command execution