Interface CommandListener
CommandClient
and used to handle events relating to Commands.- Author:
- John Grosh (jagrosh)
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidonCommand(CommandEvent event, Command command) Called when aCommandis triggered by aCommandEvent.default voidonCommandException(CommandEvent event, Command command, Throwable throwable) default voidonCompletedCommand(CommandEvent event, Command command) Called when aCommandis triggered by aCommandEventafter it's completed successfully.default voidCalled when aMessageContextMenuis triggered by aMessageContextMenuEventafter it's completed successfully.default voidonCompletedSlashCommand(SlashCommandEvent event, SlashCommand command) Called when aSlashCommandis triggered by aSlashCommandEventafter it's completed successfully.default voidCalled when aUserContextMenuis triggered by aUserContextMenuEventafter it's completed successfully.default voidCalled when aMessageContextMenuis triggered by aMessageContextMenuEvent.default voidonMessageContextMenuException(MessageContextMenuEvent event, MessageContextMenu menu, Throwable throwable) Called when aContextMenucatches aThrowableduring execution.default voidonNonCommandMessage(net.dv8tion.jda.api.events.message.MessageReceivedEvent event) Called when aMessageReceivedEventis caught by the Client Listener's but doesn't correspond to aCommand.default voidonSlashCommand(SlashCommandEvent event, SlashCommand command) Called when aSlashCommandis triggered by aSlashCommandEvent.default voidonSlashCommandException(SlashCommandEvent event, SlashCommand command, Throwable throwable) Called when aSlashCommandcatches aThrowableduring execution.default voidonTerminatedCommand(CommandEvent event, Command command) Called when aCommandis triggered by aCommandEventbut is terminated before completion.default voidCalled when aMessageContextMenuis triggered by aMessageContextMenuEventbut is terminated before completion.default voidonTerminatedSlashCommand(SlashCommandEvent event, SlashCommand command) Called when aSlashCommandis triggered by aSlashCommandEventbut is terminated before completion.default voidCalled when aUserContextMenuis triggered by aUserContextMenuEventbut is terminated before completion.default voidonUserContextMenu(UserContextMenuEvent event, UserContextMenu menu) Called when aUserContextMenuis triggered by aUserContextMenuEvent.default voidonUserContextMenuException(UserContextMenuEvent event, UserContextMenu menu, Throwable throwable) Called when aContextMenucatches aThrowableduring execution.
-
Method Details
-
onCommand
Called when aCommandis triggered by aCommandEvent.- Parameters:
event- The CommandEvent that triggered the Commandcommand- The Command that was triggered
-
onSlashCommand
Called when aSlashCommandis triggered by aSlashCommandEvent.- Parameters:
event- The SlashCommandEvent that triggered the Commandcommand- The SlashCommand that was triggered
-
onMessageContextMenu
Called when aMessageContextMenuis triggered by aMessageContextMenuEvent.- Parameters:
event- The MessageContextMenuEvent that triggered the MessageContextMenumenu- The MessageContextMenu that was triggered
-
onUserContextMenu
Called when aUserContextMenuis triggered by aUserContextMenuEvent.- Parameters:
event- The UserContextMenuEvent that triggered the UserContextMenumenu- The UserContextMenu that was triggered
-
onCompletedCommand
Called when aCommandis triggered by aCommandEventafter 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 Commandcommand- The Command that was triggered
-
onCompletedSlashCommand
Called when aSlashCommandis triggered by aSlashCommandEventafter 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 Commandcommand- The SlashCommand that was triggered
-
onCompletedMessageContextMenu
Called when aMessageContextMenuis triggered by aMessageContextMenuEventafter 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 Menumenu- The MessageContextMenu that was triggered
-
onCompletedUserContextMenu
Called when aUserContextMenuis triggered by aUserContextMenuEventafter 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 Menumenu- The MessageContextMenu that was triggered
-
onTerminatedCommand
Called when aCommandis triggered by aCommandEventbut is terminated before completion.- Parameters:
event- The CommandEvent that triggered the Commandcommand- The Command that was triggered
-
onTerminatedSlashCommand
Called when aSlashCommandis triggered by aSlashCommandEventbut is terminated before completion.- Parameters:
event- The SlashCommandEvent that triggered the Commandcommand- The SlashCommand that was triggered
-
onTerminatedMessageContextMenu
Called when aMessageContextMenuis triggered by aMessageContextMenuEventbut is terminated before completion.- Parameters:
event- The ContextMenuEvent that triggered the Context Menumenu- The ContextMenu that was triggered
-
onTerminatedUserContextMenu
Called when aUserContextMenuis triggered by aUserContextMenuEventbut is terminated before completion.- Parameters:
event- The ContextMenuEvent that triggered the Context Menumenu- The ContextMenu that was triggered
-
onNonCommandMessage
default void onNonCommandMessage(net.dv8tion.jda.api.events.message.MessageReceivedEvent event) Called when aMessageReceivedEventis caught by the Client Listener's but doesn't correspond to aCommand.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
Called when aCommandcatches aThrowableduring 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.Categorytest: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
NullPointerExceptionthrown will not be caught by this method!- Parameters:
event- The CommandEvent that triggered the Commandcommand- The Command that was triggeredthrowable- The Throwable thrown during Command execution
-
onSlashCommandException
default void onSlashCommandException(SlashCommandEvent event, SlashCommand command, Throwable throwable) Called when aSlashCommandcatches aThrowableduring execution.This doesn't account for exceptions thrown during other pre-checks, and should not be treated as such!
The
NullPointerExceptionthrown will not be caught by this method!- Parameters:
event- The CommandEvent that triggered the Commandcommand- The Command that was triggeredthrowable- The Throwable thrown during Command execution
-
onMessageContextMenuException
default void onMessageContextMenuException(MessageContextMenuEvent event, MessageContextMenu menu, Throwable throwable) Called when aContextMenucatches aThrowableduring execution.This doesn't account for exceptions thrown during other pre-checks, and should not be treated as such!
The
NullPointerExceptionthrown will not be caught by this method!- Parameters:
event- The Context Menu Event that triggered the ContextMenumenu- The Context Menu that was triggeredthrowable- The Throwable thrown during Command execution
-
onUserContextMenuException
default void onUserContextMenuException(UserContextMenuEvent event, UserContextMenu menu, Throwable throwable) Called when aContextMenucatches aThrowableduring execution.This doesn't account for exceptions thrown during other pre-checks, and should not be treated as such!
The
NullPointerExceptionthrown will not be caught by this method!- Parameters:
event- The Context Menu Event that triggered the ContextMenumenu- The Context Menu that was triggeredthrowable- The Throwable thrown during Command execution
-