public interface CommandListener
CommandClient
and used to handle events relating to Command
s.Modifier and Type | Method and Description |
---|---|
default void |
onCommand(CommandEvent event,
Command command)
Called when a
Command is triggered
by a CommandEvent . |
default void |
onCommandException(CommandEvent event,
Command command,
java.lang.Throwable throwable)
Called when a
Command
catches a Throwable during execution. |
default void |
onCompletedCommand(CommandEvent event,
Command command)
Called when a
Command is triggered
by a CommandEvent after it's
completed successfully. |
default void |
onNonCommandMessage(net.dv8tion.jda.core.events.message.MessageReceivedEvent event)
Called when a
MessageReceivedEvent
is caught by the Client Listener's but doesn't correspond to a
Command . |
default void |
onTerminatedCommand(CommandEvent event,
Command command)
Called when a
Command is triggered
by a CommandEvent but is
terminated before completion. |
default void onCommand(CommandEvent event, Command command)
Command
is triggered
by a CommandEvent
.event
- The CommandEvent that triggered the Commandcommand
- The Command that was triggereddefault void onCompletedCommand(CommandEvent event, Command command)
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
event
- The CommandEvent that triggered the Commandcommand
- The Command that was triggereddefault void onTerminatedCommand(CommandEvent event, Command command)
Command
is triggered
by a CommandEvent
but is
terminated before completion.event
- The CommandEvent that triggered the Commandcommand
- The Command that was triggereddefault void onNonCommandMessage(net.dv8tion.jda.core.events.message.MessageReceivedEvent event)
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.
event
- A MessageReceivedEvent that wasn't used to call a Commanddefault void onCommandException(CommandEvent event, Command command, java.lang.Throwable throwable)
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
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!event
- The CommandEvent that triggered the Commandcommand
- The Command that was triggeredthrowable
- The Throwable thrown during Command execution