Interface CommandListener
CommandClient
and used to handle events relating to Command
s.- Author:
- John Grosh (jagrosh)
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
onCommand
(CommandEvent event, Command command) Called when aCommand
is triggered by aCommandEvent
.default void
onCommandException
(CommandEvent event, Command command, Throwable throwable) default void
onCompletedCommand
(CommandEvent event, Command command) Called when aCommand
is triggered by aCommandEvent
after it's completed successfully.default void
Called when aMessageContextMenu
is triggered by aMessageContextMenuEvent
after it's completed successfully.default void
onCompletedSlashCommand
(SlashCommandEvent event, SlashCommand command) Called when aSlashCommand
is triggered by aSlashCommandEvent
after it's completed successfully.default void
Called when aUserContextMenu
is triggered by aUserContextMenuEvent
after it's completed successfully.default void
Called when aMessageContextMenu
is triggered by aMessageContextMenuEvent
.default void
onMessageContextMenuException
(MessageContextMenuEvent event, MessageContextMenu menu, Throwable throwable) Called when aContextMenu
catches aThrowable
during execution.default void
onNonCommandMessage
(net.dv8tion.jda.api.events.message.MessageReceivedEvent event) Called when aMessageReceivedEvent
is caught by the Client Listener's but doesn't correspond to aCommand
.default void
onSlashCommand
(SlashCommandEvent event, SlashCommand command) Called when aSlashCommand
is triggered by aSlashCommandEvent
.default void
onSlashCommandException
(SlashCommandEvent event, SlashCommand command, Throwable throwable) Called when aSlashCommand
catches aThrowable
during execution.default void
onTerminatedCommand
(CommandEvent event, Command command) Called when aCommand
is triggered by aCommandEvent
but is terminated before completion.default void
Called when aMessageContextMenu
is triggered by aMessageContextMenuEvent
but is terminated before completion.default void
onTerminatedSlashCommand
(SlashCommandEvent event, SlashCommand command) Called when aSlashCommand
is triggered by aSlashCommandEvent
but is terminated before completion.default void
Called when aUserContextMenu
is triggered by aUserContextMenuEvent
but is terminated before completion.default void
onUserContextMenu
(UserContextMenuEvent event, UserContextMenu menu) Called when aUserContextMenu
is triggered by aUserContextMenuEvent
.default void
onUserContextMenuException
(UserContextMenuEvent event, UserContextMenu menu, Throwable throwable) Called when aContextMenu
catches aThrowable
during execution.
-
Method Details
-
onCommand
Called when aCommand
is triggered by aCommandEvent
.- Parameters:
event
- The CommandEvent that triggered the Commandcommand
- The Command that was triggered
-
onSlashCommand
Called when aSlashCommand
is triggered by aSlashCommandEvent
.- Parameters:
event
- The SlashCommandEvent that triggered the Commandcommand
- The SlashCommand that was triggered
-
onMessageContextMenu
Called when aMessageContextMenu
is triggered by aMessageContextMenuEvent
.- Parameters:
event
- The MessageContextMenuEvent that triggered the MessageContextMenumenu
- The MessageContextMenu that was triggered
-
onUserContextMenu
Called when aUserContextMenu
is triggered by aUserContextMenuEvent
.- Parameters:
event
- The UserContextMenuEvent that triggered the UserContextMenumenu
- The UserContextMenu that was triggered
-
onCompletedCommand
Called when aCommand
is triggered by aCommandEvent
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 Commandcommand
- The Command that was triggered
-
onCompletedSlashCommand
Called when aSlashCommand
is triggered by aSlashCommandEvent
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 Commandcommand
- The SlashCommand that was triggered
-
onCompletedMessageContextMenu
Called when aMessageContextMenu
is triggered by aMessageContextMenuEvent
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 Menumenu
- The MessageContextMenu that was triggered
-
onCompletedUserContextMenu
Called when aUserContextMenu
is triggered by aUserContextMenuEvent
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 Menumenu
- The MessageContextMenu that was triggered
-
onTerminatedCommand
Called when aCommand
is triggered by aCommandEvent
but is terminated before completion.- Parameters:
event
- The CommandEvent that triggered the Commandcommand
- The Command that was triggered
-
onTerminatedSlashCommand
Called when aSlashCommand
is triggered by aSlashCommandEvent
but is terminated before completion.- Parameters:
event
- The SlashCommandEvent that triggered the Commandcommand
- The SlashCommand that was triggered
-
onTerminatedMessageContextMenu
Called when aMessageContextMenu
is triggered by aMessageContextMenuEvent
but is terminated before completion.- Parameters:
event
- The ContextMenuEvent that triggered the Context Menumenu
- The ContextMenu that was triggered
-
onTerminatedUserContextMenu
Called when aUserContextMenu
is triggered by aUserContextMenuEvent
but 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 aMessageReceivedEvent
is 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 aCommand
catches aThrowable
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 Commandcommand
- The Command that was triggeredthrowable
- The Throwable thrown during Command execution
-
onSlashCommandException
default void onSlashCommandException(SlashCommandEvent event, SlashCommand command, Throwable throwable) Called when aSlashCommand
catches aThrowable
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 Commandcommand
- The Command that was triggeredthrowable
- The Throwable thrown during Command execution
-
onMessageContextMenuException
default void onMessageContextMenuException(MessageContextMenuEvent event, MessageContextMenu menu, Throwable throwable) Called when aContextMenu
catches aThrowable
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 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 aContextMenu
catches aThrowable
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 ContextMenumenu
- The Context Menu that was triggeredthrowable
- The Throwable thrown during Command execution
-