Skip to content

Error Handling

Exceptions

JDA-Commands defines a set of custom runtime exceptions that can occur:

If a ConfigurationException or InvalidDeclarationException occurs during startup, JDA-Commands will shut down itself as well as JDA. To disable this behaviour, set JDACBuilder#shutdownJDA(boolean) to false.

Error Messages

As mentioned before, JDA-Commands has a set of error messages it uses all over the place. These messages include:

You can customize these error messages by providing an implementation of ErrorMessageFactory. You have to register it at the JDA-Commands Builder:

JDACommands.builder(jda, Main.class)
    .errorMessageFactory(new OwnErrorMessageFactory());
    .start();
Or use the @Implementation annotation (requires the Guice Extension):
@Implementation
public class OwnErrorMessageFactory implements ErrorMessageFactory {...}

To make things easier, these error messages can also be loaded from a JSON source using the Embed API. Therefore, you have to pass an EmbedDataSource to the EmbedConfig.

JDACommands.builder(jda, Main.class)
    .embeds(config -> config.errorSource(EmbedDataSource.file(Path.of("errorEmbeds.json")))
    .start();
The template for the error messages can be found here. The { $placeholders } can be placed anywhere in the embeds and will get injected by JDA-Commands.