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
onCompletedSlashCommand
(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aSlashCommand
is triggered by aSlashCommandEvent
after it's completed successfully.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
(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aSlashCommand
is triggered by aSlashCommandEvent
.default void
onSlashCommandException
(net.dv8tion.jda.api.events.interaction.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
onTerminatedSlashCommand
(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aCommand
is triggered by aSlashCommandEvent
but is terminated before completion.
-
Method Details
-
onCommand
Called when aCommand
is 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 aSlashCommand
is triggered by aSlashCommandEvent
.- Parameters:
event
- The SlashCommandEvent that triggered the Commandcommand
- The SlashCommand 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
default void onCompletedSlashCommand(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) 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
-
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
default void onTerminatedSlashCommand(net.dv8tion.jda.api.events.interaction.SlashCommandEvent event, SlashCommand command) Called when aCommand
is triggered by aSlashCommandEvent
but 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 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
Category
test:
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!"); } }
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(net.dv8tion.jda.api.events.interaction.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
-