Interface InvocationHandler

All Known Subinterfaces:
AnyCommandHandler, InteractionInvocationHandler, MessageInvocationHandler, SlashInvocationHandler

public sealed interface InvocationHandler permits MessageInvocationHandler, SlashInvocationHandler
A function that handles the execution of a command.
Since:
1.0
Version:
1.0
  • Method Details

    • handle

      Mono<CommandResult> handle(AnyCommandContext context) throws Exception
      Handles an invocation of the command.

      If this handler throws an exception, or the returned Mono results into an exception, the exception is automatically converted into an exception result.

      Parameters:
      context - The invocation context.
      Returns:
      The invocation result. It may result in an error (exception) if an error occured during handling (same as if this handler threw an exception directly).
      Throws:
      Exception - if an error occurred during handling.
      API Note:
      A handler is allowed to throw checked exceptions in order to simplify error handling. If an exception occurs, the usual course of action would be to return it as an exception result. Thus, it makes more sense to allow it to propagate up, then have the centralized handler automatically wrap the exception into an error, rather than clutter every handler with similar exception handling just for that purpose.

      If an exception requires handling to avoid leaving the system in an inconsistent or dangerous state, it may be implemented either in the handler itself, or in a ResultHandler that detects and handles the resulting error.

      The same logic applies to the returned Mono being allowed to result in an error. Of course, in that case there is no way to allow checked exceptions, so those would still need to be wrapped into an unchecked exception or manually returned as an exception result.