Added a way to catch errors on command execution

Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
Louis Vallat 2021-05-13 11:53:01 +02:00
parent 720a0596dd
commit 3632e77b0b

View File

@ -49,7 +49,10 @@ public final class DiscordManager {
discordClient.getEventDispatcher().on(MessageCreateEvent.class)
.filter(event -> event.getMessage().getAuthor().map(user -> !user.isBot()).orElse(false))
.filter(event -> event.getMessage().getContent().split(" ")[0].equals(command.getName()))
.flatMap(event -> !isInMaintenanceMode() ? command.execute(event).then() : Mono.just("").then())
.flatMap(event -> !isInMaintenanceMode() ? command.execute(event).then() : Mono.empty())
.doOnError(e -> logger.warn("An error occurred while executing a command " +
"('" + command.getName() + "'):", e))
.onErrorResume(e -> Mono.empty())
.subscribe();
}