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:

Localization

For simple localization of these error messages you can add a jdac_LOCALE.ftl file to the resources folder and provide the keys/ use the variables as listed below.

Type Adapting Failed

Type Adapter Error Message

Keys

  • adapting-failed-title
  • adapting-failed-details
  • adapting-failed-message

Variables

  • command: The full command with parameter names, with the failed argument underlined, for instance: /example arg1 ^^arg2^^
  • expected: The expected argument type
  • actual: The provided argument type
  • raw: The raw, textual user input
  • message: The error message of the type adapter

Insufficient Permissions

Permissions Error Message

Keys

  • insufficient-permissions

Variables

  • interaction: The name of the interaction that failed
  • permissions: The permissions that are required

Constraint Failed

Validator Error Message

Keys

  • constraint-failed

Variables

  • message: The already localized error message of the failed constraint

Interaction Execution Failed

Exception Error Message

Keys

  • execution-failed-title
  • execution-failed-message Variables

  • user: the user executing the interaction

  • interaction: the interaction type
  • timestamp: the current timestamp
  • exception: the name of the exception class

Unknown Interaction

Expiration Message

Keys

  • unknown-interaction

You can find the default fluent file here.

Own Implementation

You can customize these error messages by providing an implementation of ErrorMessageFactory either at the builder or by annotating it with @Implementation.

Example

@Implementation
public class OwnErrorMessageFactory implements ErrorMessageFactory {...}
JDACommands.builder(jda, Main.class)
    .errorMessageFactory(new OwnErrorMessageFactory());
    .start();