Middlewares
Reading time:1 min read
Middlewares are objects or callbacks that run before any command is executed. They can do some pre-processing logic and store it in the metadata, or even prevent the command from being executed.
For general information about middlewares, you must first read the general Middlewares guide.
Usage
Creation
Either:
- Create a class that extends
AbstractCommandMiddlewareand implements thecheck()method.
import { } from '@nyx-discord/djs';
import type { , , , } from '@nyx-discord/djs';
class extends {
public async (
: ,
: ,
:
): <> {
// 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,
};
};Examples
Logging middleware
import { } from '@nyx-discord/djs';
import type { , , } from '@nyx-discord/djs';
class extends {
public async (
: ,
: ,
:
) {
.(`User ${..} is executing command ${.().}`);
return this.();
}
}