bot-commands
v0.5.3
Published
A small library for making bot commands more organised.
Downloads
19
Readme
bot-commands
A small library for making bot commands more organised.
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);