Command Structure
Commands are the core building blocks of TBL. Instead of using event listeners like bot.on(), TBL follows a command-driven model. Each command acts like a rule: when the trigger matches, the bot runs its script.
Anatomy of a Command
A command can include these parts:
- Command Name → the trigger (e.g. /start, hi, /help)
- Answer → a quick static reply before running any code (supports Markdown)
- Code Block → logic written in TBL's JavaScript-like syntax
- Keyboard → optional buttons for easy replies
- Aliases → alternative triggers for the same command
- Need Reply → makes the bot wait for the next user input
Example Command
/*
command: /start
answer: Welcome! Choose an option:
keyboard: Help,About\nContact
*/
Bot.sendMessage("Hello " + user.first_name + "!")
Answer
Answers are quick static messages. They appear before any code runs.
/*Command: /help
answer: I can do these things:
- /start → Start the bot
- /about → Info about me*/
Bot.sendMessage("Extra help details...")
Need Reply
If need_reply is set to true, the bot waits for the next user message before continuing.
/*command: /ask
answer: What is your favorite color?
need_reply: true*/
Bot.sendMessage("You answered: " + message)
Aliases
Aliases let one command have multiple triggers.
/*Command: /hello
aliases: hi, hey, hola*/
Bot.sendMessage("Hello there!")
Keyboards
Commands can show custom keyboards. Same row: use commas → Yes,No. New row: use \n → Yes\nNo.
/*Command: /menu
answer: Choose an option:
keyboard: Yes,No\nMaybe*/
Bot.sendMessage("Waiting for your choice...")
Special Commands
TBL provides special system-level commands:
- @ → Initialization (runs before any other command)
- ! → Error handler (catches runtime errors)
- @@ → Post-processing (runs after every command)
- * → Wildcard (fallback when no command matches; master handler for all update types)
- /inline_query → Handles inline queries if defined; otherwise handled by *
- /channel_update → Handles channel updates if defined; otherwise handled by *
Best Practices
- Use clear names → /buy_ticket, not /cmd69
- Use aliases for multiple triggers or languages
- Always define ! to avoid silent errors
- Keep commands modular (one task per command)
- Use /handle_{type} for any special update type
- Test async code carefully, especially with await
Important
Always define a ! command to capture and handle runtime errors.
📚 Source
This tutorial is based on the official TeleBotHost TBL Documentation. Visit their site for the most up-to-date information and advanced guides.