Skip to content

Class: CommandManager

Command manager for client

Constructors

Constructor

new CommandManager(client): CommandManager

Creates a new command manager

Parameters

client

Client

Client instance

Returns

CommandManager

Methods

[kHandleCommand]()

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

Internal

Main method for handling commands

Parameters

message

MessageModel

Message object

enhanceMessage

(msg) => void

Function to enhance message

Returns

Promise<void>


addAlias()

addAlias(alias, command): void

Adds alias for command

Parameters

alias

string

Command alias

command

string

Original command

Returns

void

Example

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

get()

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

Returns command information

Parameters

command

string

Command 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()

register(command, argsSchema, handler): void

Registers a new command

Parameters

command

string

Command name

argsSchema

CommandArgsSchema

Command arguments schema

handler

CommandHandler

Command 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()

remove(command): boolean

Removes command

Parameters

command

string

Command 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