Skip to content

Class: CommandManager

Command manager for client

Constructors

Constructor

new CommandManager(client): CommandManager

Creates a new command manager

Parameters

NameTypeDescription
clientClientClient instance

Returns

CommandManager

Methods

[kHandleCommand]()

[kHandleCommand](message, enhanceMessage): Promise<void>

Internal

Main method for handling commands

Parameters

NameTypeDescription
messageMessageModelMessage object
enhanceMessage(msg) => voidFunction to enhance message

Returns

Promise<void>


addAlias(alias, command): void

`

Adds alias for command

Parameters

NameTypeDescription
aliasstringCommand alias
commandstringOriginal command

Returns

void

Example

ts
client.commands.addAlias('h', 'help');
// Now both 'help' and 'h' will execute the same command

get(command): undefined | { argsSchema: CommandArgsSchema; description?: string; }

`

Returns command information

Parameters

NameTypeDescription
commandstringCommand name

Returns

undefined | { argsSchema: CommandArgsSchema; description?: string; }

Object with command information or undefined if command not found

Example

ts
const cmdInfo = client.commands.get('help');
if (cmdInfo) {
  console.log('Command args schema:', cmdInfo.argsSchema);
}

getAll()

getAll(): string[]

Returns list of registered commands

Returns

string[]

Array of command names

Example

ts
const commands = client.commands.getAll();
console.log('Registered commands:', commands);
// Result: Registered commands: [ 'info', 'help' ]

register(command, argsSchema, handler): void

`

Registers a new command

Parameters

NameTypeDescription
commandstringCommand name
argsSchemaCommandArgsSchemaCommand arguments schema
handlerCommandHandlerCommand handler

Returns

void

Examples

ts
client.commands.register('hello', { name: 'string' }, (message, args) => {
  console.log(`Hello, ${args.name}!`);
});
ts
client.commands.register('add', { a: 'int', b: 'int' }, (message, args) => {
  const sum = args.a + args.b;
  message.reply(`The sum is ${sum}`);
});

remove(command): boolean

`

Removes command

Parameters

NameTypeDescription
commandstringCommand name

Returns

boolean *? true if command was removed, false otherwise

Example

ts
const removed = client.commands.remove('help');
console.log('Command removed:', removed); // true or false