bot-commands

0.5.3 • Public • Published

bot-commands

A small library for making bot commands more organised.

Documentation

Usage

In this example, I use TypeScript and create a simple ping command.

import { Command, Commands } from "bot-commands";

type CustomCommandOpts = {
  user_id: number;
};

const ping_command: Command<CustomCommandOpts> = {
  help({ commands, name }, _extra_args) {
    return `format: ${commands.prefix}${name}\n\nIf I'm alive, I reply with pong!`;
  },
  run(_cmd_data, { user_id }, _extra_args) {
    return `pong! your id is ${user_id}`;
  },
};

const cmd_prefix = "!";

const commands = new Commands<CustomCommandOpts>(cmd_prefix, {
  ping: ping_command,
});

const example_input = "!ping a b c";
if (example_input.startsWith(cmd_prefix)) {
  const opts = { user_id: 1 };
  commands.run(example_input.slice(1).trim(), opts).then((result) => {
    if (result) console.log(result);
  });
}

Registering a command

After the class has been instantiated, you can register a new command like this:

commands.register("ping", ping_command);

Readme

Keywords

Package Sidebar

Install

npm i bot-commands

Weekly Downloads

1

Version

0.5.3

License

MIT

Unpacked Size

21.8 kB

Total Files

9

Last publish

Collaborators

  • kinziedev