Skip to Content
nyx logonyx guide

Middleware List

See in:
ScheduleMiddlewareListGitHub
AbstractMiddlewareListGitHub
MiddlewareListGitHub
Reading time:2 min read

The ScheduleMiddlewareList manages the middlewares that run before a schedule tick() is executed. It lives inside the ScheduleExecutor and is used by it.

Middleware Execution

Middlewares are executed sequentially. If any middleware throws an error or returns without calling next(), the schedule execution is aborted and the executor forwards the error to its configured handler.

The ScheduleFilterCheckMiddleware is a built-in middleware that runs first by default (or as configured) to check if the schedule's filter method allows execution.

When to override

✅ Override if you want to...❌ Don't override if you want to...
Customize how middlewares are stored or iterated.Add middlewares to the existing list. Use a custom ScheduleExecutor if you only need different injections.
Add priority/group ordering semantics beyond simple insertion order.Change error handling around tick() execution. That belongs to ScheduleErrorHandler.
Enforce middleware deduplication or identity-based replacement rules.Change when schedules are triggered. That belongs to ScheduleExecutionScheduler.

Overriding

Creation

Create a custom ScheduleMiddlewareList by either:

  • Extending ScheduleMiddlewareList (recommended, less work).
  • Implementing MiddlewareList<ScheduleMiddlewareResolvable>.
import {  } from '@nyx-discord/djs';

class  extends  {}

Registration

Inject it into a custom DefaultScheduleExecutor, then set that executor to the ScheduleManager.

import type {  } from '@nyx-discord/djs';
declare const : ;

const  = new (
  .(),
  .((, , []) =>
    .(),
  ),
);

.().();
Edit on GitHub

Last updated on

On this page