Middlewares
Reading time:1 min read
Middlewares are objects or callbacks that run before any schedule is executed. They can do some pre-processing logic and store it in the metadata, or even prevent the subscriber from being executed.
For general information about middlewares, you must first read the general Middlewares guide.
Usage
Creation
Either:
- Create a class that extends
AbstractScheduleMiddlewareand implements thecheck()method.
import { } from '@nyx-discord/djs';
import type { Schedule, , } from '@nyx-discord/djs';
class extends {
public async (
: Schedule,
:
): <> {
// Do some pre-processing logic
return this.();
}
}- Create a function that returns a
MiddlewareResponse.
import { type } from '@nyx-discord/djs';
const : = async (, ) => {
// Do some pre-processing logic
return {
: true,
: true,
};
};