Sign in
Telegram

Create a Telegram Bot with @BotFather: Token Setup and Command Menu

Verify the official BotFather account, create your bot, and store its token securely. Test the token and command menu separately, and replace the token if it leaks.

4 min read
Create a Telegram Bot with @BotFather: Token Setup and Command Menu

1. Verify BotFather and create your bot

  1. Search Telegram for @BotFather. Open the profile and check both the exact username and the official verification badge. Don’t rely on the avatar, display name, or a contact card forwarded in a group. If in doubt, open BotFather from the official Telegram bot documentation.
  2. In your private chat with BotFather, tap Start and send /newbot. Enter a display name, such as “Order Lookup Assistant,” then choose a username people can search for. These are separate fields; the display name can include Chinese characters.
  3. For the username, use letters (A–Z), digits, or underscores, and end it with bot, as in shop_order_bot. If it’s taken, enter another username when prompted; there’s no need to restart. Once BotFather confirms creation, open the bot link in the message and check the display name and username.
A blue paper-plane mascot stamps a star on a ceramic messenger figurine in a mint-green kiln room, illustrating the bot identity check.

2. Store the token and verify it from your backend

  1. Copy the entire API token from BotFather’s confirmation message, including the colon. The username is public, but the token is a secret: anyone who has it can call the API as your bot without signing in to your personal account.
  2. In your deployment platform’s secrets settings, create TELEGRAM_BOT_TOKEN and paste the token without quotes or extra spaces. Give the bot service access to the secret at runtime. Keep the token out of source code, frontend code, and startup commands. Redeploy so the service loads the secret.
  3. Before testing, disable debug logging that prints full request URLs, since those URLs contain the token. Use a Telegram bot library on your backend to call getMe. If the returned username matches the one from step 1, the token works and belongs to the intended bot. This does not test message delivery or replies.
A blue paper-plane mascot places a pearl key in an oyster-shaped safe inside an amber cave, illustrating secure token storage.

3. Set up the command menu

  1. Send /setcommands to BotFather and select your bot by username. Send the following two lines as a single message, without bullet points:

``` start - Get started help - Show help ``` 2. The command name goes on the left; use only lowercase English letters, digits, or underscores. The description on the right is what users see. Omit the slash when registering a command, but include it in chat: help in BotFather, /help in your bot. Wait for BotFather’s confirmation. 3. Open a private chat with your bot, tap Start, and type / to see the available commands. The menu lists commands but does not implement them. For Show help to return a reply, register a /help handler in your backend and start the service.

A blue paper-plane mascot fits two differently shaped handles to a lavender railway switch, illustrating command menu setup.

4. Troubleshoot by symptom

SymptomCheck firstWhat to do
The menu still shows old commandsDid you edit the right bot?Verify the username and reopen the private chat. If your code also sets the menu, check whether it overwrites the BotFather settings.
Tapping a command gets no replyDoes the backend receive the message?If not, check your message receiver. If the message arrives, check that the command name matches the registered handler and that the handler sends a reply.
The API returns “Unauthorized”Is the running service using an old token?Check the deployed secret version, update the environment where the bot actually runs, and restart the service. Never post the token when asking for help.
A blue paper-plane mascot traces the gears in a teal watermill to a red pebble jamming the wheel, illustrating step-by-step troubleshooting.

5. Replace a leaked token and complete handoff

If the token appears in shared screenshots, a group chat, or a code repository, deleting the exposed copy does not invalidate it. Immediately send /revoke to BotFather, select the affected bot, and obtain a replacement token. Update the secret on every running instance, restart each one, and retest both getMe and /help. Then remove the exposed copies.

  • Storage: Keep any backup in a password manager, not in Telegram Saved Messages. Enable two-step verification on the account that manages the bot; see the two-step verification guide.
  • Acceptance check: Confirm that getMe returns the intended username, the command menu appears in a private chat, and tapping /help produces the expected reply.
  • Handoff: Record who is responsible for the bot, where the secret is stored, and how to replace it. Do not include the token itself in the handoff document.