CommandControlPlugin
CommandControlPlugin<
I
>(execute
):Plugin
<unknown
[]>
Creates a control plugin for command preprocessing, filtering, and state management
Type parameters
• I extends CommandType
Extends CommandType to enforce type safety for command modules
Parameters
• execute
Function to execute during command control flow
Returns
Plugin
<unknown
[]>
A plugin that runs during command execution flow
Since
2.5.0
Example
1// Plugin to restrict command to specific guild2export const inGuild = (guildId: string) => {3 return CommandControlPlugin((ctx, sdt) => {4 if(ctx.guild.id !== guildId) {5 return controller.stop();6 }7 return controller.next();8 });9};
Example
1// Plugins passing state through the chain2const plugin1 = CommandControlPlugin((ctx, sdt) => {3 return controller.next({ 'plugin1/data': 'from plugin1' });4});5
6const plugin2 = CommandControlPlugin((ctx, sdt) => {7 return controller.next({ 'plugin2/data': ctx.user.id });8});9
10export default commandModule({11 type: CommandType.Slash,12 plugins: [plugin1, plugin2],13 execute: (ctx, sdt) => {14 console.log(sdt.state); // Access accumulated state15 }16});
Remarks
- Control plugins are executed in order when a discord.js event is emitted
- Use controller.next() to continue to next plugin or controller.stop() to halt execution
- State can be passed between plugins using controller.next({ key: value })
- State keys should be namespaced to avoid collisions (e.g., ‘plugin-name/key’)
- Final accumulated state is passed to the command’s execute function
- All plugins must succeed for the command to execute
- Plugins have access to dependencies through the sdt.deps object
- Useful for implementing preconditions, filters, and command preprocessing