Middlewares¶
Middlewares run just before an interaction event gets dispatched. They are used to perform additional checks or add more
info the InvocationContext
.
Middlewares are intended to provide a flexible system for extending the execution chain.
They are executed based on their Priority
in the following order:
PERMISSIONS
: Middlewares with this priority will always be executed firstHIGH
: Highest priority for custom implementations, will be executed right after internal middlewaresNORMAL
: Default priorityLOW
: Lowest priority, will be executed at the end
If one middleware fails, the entire interaction execution gets immediately aborted and no more middlewares will be executed.
Default Middlewares¶
JDA-Commands uses its own Middleware API internally to implement some features. All these features can either be
extended or replaced by the user. You can either register your own implementations at the respective builder method
or use the @Implementation
annotation.
Note
Using the @Implementation
annotation requires the guice integration (shipped by default). You can read more about it here.
Middlewares provided by JDA-Commands include:
Writing own Middlewares¶
You can write your own middlewares by implementing the Middleware
interface.
You can cancel an execution by calling context.cancel(message)
.
Example
Then, either register your Middleware at the builder:
JDACommands.builder(jda, Main.class)
.middleware(Priority.NORMAL, new LoggingMiddleware());
.start();
or use the @Implementation
annotation: