Class DefaultErrorMessageFactory

java.lang.Object
io.github.kaktushose.jdac.embeds.error.DefaultErrorMessageFactory
All Implemented Interfaces:
ErrorMessageFactory

public final class DefaultErrorMessageFactory extends Object implements ErrorMessageFactory

The default implementation of ErrorMessageFactory using Components V2.

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

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

Keys

  • insufficient-permissions

Variables

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

Constraint Failed

Keys

  • constraint-failed

Variables

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

Interaction Execution Failed

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

Keys

  • unknown-interaction

Own Implementation

Alternatively, you can pass your own ErrorMessageFactory implementation to JDACBuilder.errorMessageFactory(ErrorMessageFactory).

  • Constructor Details

    • DefaultErrorMessageFactory

      public DefaultErrorMessageFactory(MessageResolver resolver)
  • Method Details

    • getTypeAdaptingFailedMessage

      public net.dv8tion.jda.api.components.MessageTopLevelComponent getTypeAdaptingFailedMessage(ErrorMessageFactory.ErrorContext context, io.github.kaktushose.proteus.conversion.ConversionResult.Failure<?> failure)
      Gets a MessageTopLevelComponent to send when type adapting of the user input failed.
      Specified by:
      getTypeAdaptingFailedMessage in interface ErrorMessageFactory
      Parameters:
      context - the ErrorMessageFactory.ErrorContext
      failure - the ConversionResult.Failure
      Returns:
      a MessageTopLevelComponent to send when type adapting failed
    • getInsufficientPermissionsMessage

      public net.dv8tion.jda.api.components.MessageTopLevelComponent getInsufficientPermissionsMessage(ErrorMessageFactory.ErrorContext context)
      Gets a MessageTopLevelComponent to send when a user is missing permissions.
      Specified by:
      getInsufficientPermissionsMessage in interface ErrorMessageFactory
      Parameters:
      context - the ErrorMessageFactory.ErrorContext
      Returns:
      a MessageTopLevelComponent to send when a user is missing permissions
    • getConstraintFailedMessage

      public net.dv8tion.jda.api.components.MessageTopLevelComponent getConstraintFailedMessage(ErrorMessageFactory.ErrorContext context, String message)
      Gets a MessageTopLevelComponent to send when a parameter constraint fails.
      Specified by:
      getConstraintFailedMessage in interface ErrorMessageFactory
      Parameters:
      context - the ErrorMessageFactory.ErrorContext
      Returns:
      a MessageTopLevelComponent to send when a parameter constraint fails
    • getInteractionExecutionFailedMessage

      public net.dv8tion.jda.api.components.MessageTopLevelComponent getInteractionExecutionFailedMessage(ErrorMessageFactory.ErrorContext context, Throwable exception)
      Gets a MessageTopLevelComponent to send when the command execution failed.
      Specified by:
      getInteractionExecutionFailedMessage in interface ErrorMessageFactory
      Parameters:
      context - the ErrorMessageFactory.ErrorContext
      exception - the Throwable that made the command execution fail
      Returns:
      a MessageTopLevelComponent to send when the command execution failed
    • getTimedOutComponentMessage

      public net.dv8tion.jda.api.components.MessageTopLevelComponent getTimedOutComponentMessage(net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent event)
      Gets a MessageTopLevelComponent to send when an incoming component interaction already timed out.
      Specified by:
      getTimedOutComponentMessage in interface ErrorMessageFactory
      Parameters:
      event - the GenericInteractionCreateEvent mo runtime was found for
      Returns:
      a MessageTopLevelComponent to send when an incoming component interaction already timed out