Error Handling¶
Exceptions¶
JDA-Commands defines a set of custom runtime exceptions that can occur:
- ConfigurationException will be thrown if anything goes wrong while configuring JDA-Commands.
- InvalidDeclarationException will be thrown if any errors are made in the declaration of interactions.
- InternalException will be thrown if anything goes wrong internally. These errors should be reported to the devs.
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:
- Command Execution Failed Message (used for Exceptions)
- Constraint Failed Message (see Validators)
- Cooldown Message (see Command Cooldown)
- Insufficient Permissions Message (see Permissions System)
- Timed Out Component Message (see Runtime Concept)
- Type Adapting Failed Message (see Type Adapters)
You can customize these error messages by providing an implementation of ErrorMessageFactory. You have to register it at the JDA-Commands Builder:
Or use the@Implementation annotation (requires the Guice Extension):
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();
{ $placeholders } can be placed anywhere in the embeds and will get injected by JDA-Commands.