
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@grammyjs/commands
Advanced tools
This plugin provides a convenient way to define and manage commands for your grammY bot. It simplifies the process of setting up commands with scopes and localization.
npm i @grammyjs/commands
The main functionality of this plugin is to define your commands, localize them, and give them handlers for each scope, like so:
import { Bot } from "grammy";
import { CommandGroup } from "@grammyjs/commands";
const bot = new Bot("<telegram token>");
const myCommands = new CommandGroup();
myCommands.command("start", "Initializes bot configuration")
.localize("pt", "start", "Inicializa as configurações do bot")
.addToScope(
{ type: "all_private_chats" },
(ctx) => ctx.reply(`Hello, ${ctx.chat.first_name}!`),
)
.addToScope(
{ type: "all_group_chats" },
(ctx) => ctx.reply(`Hello, members of ${ctx.chat.title}!`),
);
// Calls `setMyCommands`
await myCommands.setCommands(bot);
// Registers the command handlers
bot.use(myCommands);
bot.start();
It is very important that you call bot.use
with your instance of the Commands
class. Otherwise, the command handlers
will not be registered, and your bot will not respond to those commands.
This plugin provides a shortcut for setting the commands for the current chat. To use it, you need to install the commands flavor and the plugin itself, like so:
import { Bot, Context } from "grammy";
import { CommandGroup, commands, CommandsFlavor } from "@grammyjs/commands";
type BotContext = CommandsFlavor;
const bot = new Bot<BotContext>("<telegram_token>");
bot.use(commands());
bot.on("message", async (ctx) => {
const cmds = new CommandGroup();
cmds.command("start", "Initializes bot configuration")
.localize("pt", "start", "Inicializa as configurações do bot");
await ctx.setMyCommands(cmds);
return ctx.reply("Commands set!");
});
bot.start();
FAQs
grammY Commands Plugin
We found that @grammyjs/commands demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.