telegraf-command-handler-upgraded
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

Telegraf Command Handler Upgraded

A command handler for Telegraf, which is similar to the command handler for Discord.js and such. The goal is that all commands are not in 1 file... But divided into several different files.

Installation

npm i telegraf-command-handler-upgraded
# or
yarn add telegraf-command-handler-upgraded
# or
pnpm add telegraf-command-handler-upgraded

Usage

/* main file */
const { Telegraf } = require('telegraf');
const { TelegrafCommandHandler } = require('telegraf-command-handler-upgraded');
const path = require('path');

const bot = new Telegraf('Your bot token');

const CommandHandler = new TelegrafCommandHandler({
    path: path.resolve() + "/path/to/dir",
});

bot.use(CommandHandler.load());

// ...bot.launch()
/* command file */
module.exports = {
    name: "start",
    async execute(ctx) {
        ctx.reply("hello world");
    }
}

Constructor Options

interface Options {
    /* path to your command directory */
    path: string;
    /* a function that executed when error comes from your command file */
    errorHandling: (ctx: Context, error: any) => any | undefined;
}

Command Example

module.exports = {
    /* command name (it will executed like /echo) */
    name: "echo",
    /* optional command aliases (can be string or Array<string>) */
    aliases: ["say"],
    /* command code */
    async execute(ctx, args) {
        ctx.reply(args.join(" "))
    }
}

Package Sidebar

Install

npm i telegraf-command-handler-upgraded

Weekly Downloads

2

Version

1.2.2

License

MIT

Unpacked Size

10.6 kB

Total Files

12

Last publish

Collaborators

  • mscodepl