getMyCommands
Returns: BotCommand[]Official docs ↗
Use this method to get the current list of the bot's commands for the given scope and user language. Returns an Array of BotCommand objects. If commands aren't set, an empty list is returned.
Parameters
A JSON-serialized object, describing scope of users. Defaults to BotCommandScopeDefault.
language_codeStringOptionalA two-letter ISO 639-1 language code or an empty string
Returns
On success, an array of BotCommand objects is returned.
GramIO Usage
ts
// Get the bot's default commands (all users, all chats)
const commands = await bot.api.getMyCommands({});
console.log(commands); // [] if no default commands are setts
// Get commands scoped to private chats only
const privateCommands = await bot.api.getMyCommands({
scope: { type: "all_private_chats" },
});
// Get commands for all group chat administrators
const adminCommands = await bot.api.getMyCommands({
scope: { type: "all_chat_administrators" },
});ts
// Get localized commands for a specific language
const ruCommands = await bot.api.getMyCommands({
scope: { type: "default" },
language_code: "ru",
});
const enCommands = await bot.api.getMyCommands({
scope: { type: "default" },
language_code: "en",
});
console.log("RU:", ruCommands);
console.log("EN:", enCommands);ts
// Get commands for a specific user in a specific chat
const userCommands = await bot.api.getMyCommands({
scope: {
type: "chat_member",
chat_id: -1001234567890,
user_id: 987654321,
},
language_code: "en",
});
// Display the command list
for (const cmd of userCommands) {
console.log(`/${cmd.command} — ${cmd.description}`);
}ts
// Audit all scopes by checking a few key ones
const [defaults, groups, privateChats] = await Promise.all([
bot.api.getMyCommands({}),
bot.api.getMyCommands({ scope: { type: "all_group_chats" } }),
bot.api.getMyCommands({ scope: { type: "all_private_chats" } }),
]);
console.log("Default:", defaults.map((c) => c.command));
console.log("Groups: ", groups.map((c) => c.command));
console.log("Private:", privateChats.map((c) => c.command));Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: SCOPE_UNSUPPORTED | scope.type is not a valid value — use one of the documented BotCommandScope types |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use the auto-retry plugin |
Tips & Gotchas
- Both parameters are optional. Omitting
scopedefaults to{ type: "default" }; omittinglanguage_codedefaults to an empty string (language-agnostic fallback commands). - Returns empty array if no commands are set. This is not an error — it simply means
setMyCommandshas never been called for that scope/language combination. - Scope resolution is hierarchical. Telegram shows the most specific command set that matches the user's context. If
chat_memberscope has commands, those overrideall_group_chats, which overridesdefault.getMyCommandsreads one specific scope — it does not simulate the resolution chain. - Language overrides the base scope. If you set English commands for the
defaultscope,getMyCommands({ language_code: "en" })returns those. Users with a different language fall back to the language-agnostic version. language_codemust be ISO 639-1 (e.g.,"en","ru","de"). An empty string""reads the commands without a language filter.- Up to 100 commands per scope+language. Each command description is limited to 1–256 characters; command names must be lowercase and match
/[a-z0-9_]{1,32}/.
See Also
- BotCommand — return type element
- BotCommandScope — union type for all scope variants
- setMyCommands — set commands for a scope
- deleteMyCommands — remove commands for a scope
- getMe — get the bot's identity and capabilities