Middleware List
Reading time:2 min read
The SubscriberMiddlewareList holds and executes the middlewares used by an EventDispatcher before each subscriber is called.
It's inside the CommandExecutor object, and will be used by it.
When to override
| ✅ Override if you want to... | ❌ Don't override if you want to... |
|---|---|
| Add custom behavior before/after middleware checks. | Change subscriber execution order. That's controlled by the bus and its sorter. |
| Change how middleware errors are wrapped or reported. | Handle subscriber errors. Use the dispatcher's ErrorHandler for that. |
| Replace the default middleware chain globally for a dispatcher. | Override all dispatcher logic. If only middleware behavior changes, replacing the list is enough. |
Overriding
Creation
Create a custom middleware list by either:
- Extending
SubscriberMiddlewareList(recommended, less work). - Implementing
MiddlewareList<EventSubscriberMiddlewareResolvable>.
import { } from '@nyx-discord/djs';
class extends {}Registration
Inject it directly when creating the dispatcher:
import { } from '@nyx-discord/djs';
// Works the same with the async dispatcher
const = .({
: {
: .(),
},
});
.();If you prefer, you can still wrap this in a custom dispatcher class and call super.create(...).
Edit on GitHub
Last updated on
