Saltearse al contenido
sern

CommandInitPlugin

CommandInitPlugin<I>(execute): Plugin

Creates an initialization plugin for command preprocessing and modification

Type parameters

I extends CommandType

Extends CommandType to enforce type safety for command modules

Parameters

execute

Function to execute during command initialization

Returns

Plugin

A plugin that runs during command initialization

Since

2.5.0

Example

1
// Plugin to update command description
2
export const updateDescription = (description: string) => {
3
return CommandInitPlugin(({ deps }) => {
4
if(description.length > 100) {
5
deps.logger?.info({ message: "Invalid description" })
6
return controller.stop("From updateDescription: description is invalid");
7
}
8
module.description = description;
9
return controller.next();
10
});
11
};

Example

1
// Plugin to store registration date in module locals
2
export const dateRegistered = () => {
3
return CommandInitPlugin(({ module }) => {
4
module.locals.registered = Date.now()
5
return controller.next();
6
});
7
};

Remarks

  • Init plugins can modify how commands are loaded and perform preprocessing
  • The module.locals object can be used to store custom plugin-specific data
  • Be careful when modifying module fields as multiple plugins may interact with them
  • Use controller.next() to continue to the next plugin
  • Use controller.stop(reason) to halt plugin execution

Source

src/core/plugin.ts:62