use of net.robinfriedli.aiode.command.CommandContext in project aiode by robinfriedli.
the class ExceptionUtils method handleCommandException.
public static void handleCommandException(Throwable e, Command command, Logger logger) {
if (e instanceof CommandFailure) {
return;
}
CommandContext commandContext = command.getContext();
if (Aiode.isShuttingDown()) {
logger.warn(String.format("Suppressed error from command %s because it happened during shutdown: %s", commandContext.getId(), e));
return;
}
MessageChannel channel = commandContext.getChannel();
String commandDisplay = command.display();
MessageService messageService = Aiode.get().getMessageService();
if (e instanceof UserException) {
EmbedBuilder embedBuilder = ((UserException) e).buildEmbed();
messageService.sendTemporary(embedBuilder.build(), channel);
} else {
EmbedBuilder embedBuilder = ExceptionUtils.buildErrorEmbed(e);
embedBuilder.addField("CommandContext ID", commandContext.getId(), false);
messageService.send(embedBuilder.build(), channel);
logger.error(String.format("Exception while handling command %s on guild %s", commandDisplay, commandContext.getGuild().getName()), e);
}
}
Aggregations