Skip to Content
nyx logonyx guide

Middlewares

Reading time:1 min read

Middlewares are objects or callbacks that run before any subscriber 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 AbstractEventSubscriberMiddleware and implements the check() 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,
  };
};

Registration

Register it to the dispatcher's MiddlewareList:

.().().(new (), );
Edit on GitHub

Last updated on

On this page