Socket
Book a DemoInstallSign in
Socket

@grammyjs/commands

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grammyjs/commands

grammY Commands Plugin

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
2
Created
Source

grammY commands

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.

Installation

npm i @grammyjs/commands

Usage

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.

Context shortcuts

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

Keywords

grammY

FAQs

Package last updated on 21 Aug 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.