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 voidonCompletedSlashCommand(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aSlashCommandis triggered by aSlashCommandEventafter it's completed successfully.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(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aSlashCommandis triggered by aSlashCommandEvent.default voidonSlashCommandException(net.dv8tion.jda.api.events.interaction.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 voidonTerminatedSlashCommand(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aCommandis triggered by aSlashCommandEventbut is terminated before completion.
-
Method Details
-
onCommand
Called when aCommandis triggered by aCommandEvent.- Parameters:
event- The CommandEvent that triggered the Commandcommand- The Command that was triggered
-
onSlashCommand
default void onSlashCommand(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aSlashCommandis triggered by aSlashCommandEvent.- Parameters:
event- The SlashCommandEvent that triggered the Commandcommand- The SlashCommand 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
default void onCompletedSlashCommand(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) 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
-
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
default void onTerminatedSlashCommand(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aCommandis triggered by aSlashCommandEventbut is terminated before completion.- Parameters:
event- The SlashCommandEvent that triggered the Commandcommand- The SlashCommand 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
Categorytest:
Thepublic 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!"); } }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(net.dv8tion.jda.api.events.interaction.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
-