How to Add Commands to Your Bot
Once your bot is created, it's time to make it do things — and that starts with commands!
Managing Commands in Bots Mother
This guide details how to set up and manage commands for your Telegram bot in the Bots Mother platform. It covers adding, editing, and deleting commands, configuring their settings, and using the special *
(master) command with configurations like *
(default), ((
(run before), ))
(run after), !!
(error handler), #
(webhook updates), and ##
(webhook message updates) to manage unmatched inputs, command execution flow, errors, and Telegram updates. Create robust bot interactions with ease.
Step 1: Open Your Bot’s Command Panel
To manage your bot’s commands, access the Commands tab in Bots Mother:
Go to Bots Mother: Log in to the Bots Mother platform.
Click “My Bots”: From the dashboard, select “My Bots.”
Select Your Bot: Find the bot you created and click “View.”
Go to Commands Tab: Navigate to the “Commands” tab to view all existing commands (if any) and the option to “Add Command.”
Adding a New Command
Create a new command to define how your bot responds to user input:
Click “Add Command”: In the Commands tab, click “Add Command” to open the form.
Fill Out the Form:
Command: Specify the command name (e.g.,
/start
,/help
) that users will type to trigger the action. For the master command, use one of the special configurations:*
,((
,))
,!!
,#
, or##
(see below).Alias (optional): Add alternative triggers (e.g.,
/hi
,/hello
) to activate the same command. Note: Special symbols (*
,((
,))
,!!
,#
,##
) cannot be used in the Alias field; they must be set in the Command field.Auto Answer (optional): Set a message to be sent automatically when the command is triggered. Ideal for quick replies or simple bots.
Keyboards (optional): Attach custom Telegram keyboards (e.g., buttons) to the auto-answer for user interaction, no coding required.
Chat Type (optional): Select where the command is active:
Private (direct messages)
Group (group chats)
Channel (channels)
Leave empty to allow all chat types.
Help (optional): Provide a short description of the command’s purpose for better organization.
Placeholder (optional): Add guiding text shown to users while waiting for their reply (used with “Wait for Answer”).
Wait for Answer: Enable this to make the bot wait for user input after sending the auto-answer. When enabled:
The command’s PHP code does not run immediately.
The code executes only when the user sends their next message.
Save the Command: Submit the form to add the command to your bot.
Special Commands
The *
command is a powerful master command with special configurations defined by symbols set in the Command field. These configurations control its execution timing and behavior, handling unmatched commands, command flow, errors, and Telegram webhook updates. Each configuration requires a separate *
command with the corresponding symbol:
Default Command (
*
): Runs when no other commands match the user’s input. Use this to handle unknown or invalid commands (e.g., when a user types/unknown
).Run Before Commands (
((
): Runs before all other commands, enabling setup tasks or preprocessing (e.g., logging incoming messages).Run After Commands (
))
): Runs after all other commands, useful for cleanup or logging (e.g., confirming command execution).Error Handler (
!!
): Runs when any command encounters an error, allowing graceful error handling (e.g., notifying the user of issues).Webhook Updates (
#
): Runs for all Telegram webhook updates, including messages, callback queries, chat member changes, inline queries, and more. This configuration is unique because it processes every update received from Telegram, regardless of whether it matches a command or not, making it seem "in everywhere." Unlike other*
configurations or regular commands (e.g.,/start
), which are tied to specific user inputs or execution stages,#
is not linked to command matching or flow. It’s designed for broad update handling, such as logging all interactions or responding to non-command events (e.g., a user joining a group).Webhook Message Updates (
##
): Runs specifically for message-related webhook updates (e.g., text messages, photos, stickers, videos). This is a more focused version of#
, processing only updates that involve messages, making it ideal for message-specific logic (e.g., echoing user messages).
Key Differences of #
and ##
:
Scope:
#
captures all Telegram updates, including non-message events like callback queries or chat member updates, while##
is limited to message-related updates. This makes#
appear "in everywhere" due to its universal coverage.No Link to Other Commands: Unlike
*
(default),( (
(before),) )
(after), or!!
(error), which are tied to command execution (matching, flow, or errors),#
and##
operate independently of command logic. They process raw webhook data, allowing you to handle events that don’t involve commands (e.g., a user sending a sticker or clicking an inline button).Use Case: Use
#
for global update processing (e.g., analytics, monitoring all bot interactions) and##
for message-specific tasks (e.g., auto-responding to text or media). Regular commands (e.g.,/start
) and other*
configurations are more targeted, responding to specific user inputs or execution stages.
How to Configure the *
Command:
Click “Add Command” and set the Command field to one of the special symbols:
*
,( (
,) )
,!!
,#
, or##
.Do not add these symbols in the Alias field, as they are only valid in the Command field.
Configure other settings (e.g., Auto Answer, Wait for Answer) as needed.
In the code editor (via “Edit Code”), write PHP logic to handle the specific behavior (e.g., default responses, preprocessing, error handling, or webhook processing).
Create multiple
*
commands (one for each symbol) to cover all desired roles, as each command can only have one symbol in the Command field.
Example Use Cases:
Default (
*
): Respond with “Command not found” for unrecognized inputs.Before
( (
: Log every incoming update before command processing.After
) )
: Send a confirmation after all commands execute.Error
!!
: Notify the user of an error during command execution.Webhook Updates
#
: Log all Telegram updates or respond to non-command events like callback queries.Webhook Message Updates
##
: Auto-reply to incoming text messages or process media.
Managing Existing Commands
Once commands are added, you can modify or remove them from the Commands tab:
Edit Code: Click “Edit Code” to open the PHP code editor and write or update the command’s logic. Use Telegram webhook variables (e.g.,
$update
,$TGUser
,$chatId
) and BotAPI methods for dynamic responses.Edit Settings: Click “Edit Settings” to update the command name, aliases, auto-answer, keyboards, or other options.
Delete: Click “Delete” to remove the command entirely.
For *
commands, ensure the correct symbol (*
, ( (
, ) )
, !!
, #
, ##
) is set in the Command field to achieve the desired behavior.

Example: Setting Up Commands
Here’s an example of adding a /start
command and configuring *
commands with different roles:
Add
/start
Command:Command:
/start
Auto Answer: “Welcome! What’s your name?”
Wait for Answer: Enabled
Chat Type: Private
Help: “Greets the user and asks for their name.”
In the code editor, add:
if ($updateType === 'message') { $userName = $message; BotAPI::sendMessage([ 'chat_id' => $chatId, 'text' => "Nice to meet you, $userName!", 'parse_mode' => 'HTML' ]); }
Add Special Command (Default):
Command:
*
Auto Answer: “I didn’t understand that command.”
Wait for Answer: Disabled
Help: “Handles unrecognized commands.”
In the code editor, add:
BotAPI::sendMessage([ 'chat_id' => $chatId, 'text' => "Sorry, that command is not recognized. Try /start!", 'parse_mode' => 'HTML' ]);
Add Special Command (Run Before
((
):Command:
((
Auto Answer: None
Wait for Answer: Disabled
Help: “Logs messages before commands.”
In the code editor, add:
BotAPI::sendMessage([ 'chat_id' => $chatId, 'text' => "Processing your request...", 'parse_mode' => 'HTML' ]);
Add Special Command (Run After
))
):Command:
))
Auto Answer: None
Wait for Answer: Disabled
Help: “Confirms command execution.”
In the code editor, add:
BotAPI::sendMessage([ 'chat_id' => $chatId, 'text' => "Command processed successfully!", 'parse_mode' => 'HTML' ]);
Add Special Command (Error Handler
!!
):Command:
!!
Auto Answer: “Something went wrong.”
Wait for Answer: Disabled
Help: “Handles command errors.”
In the code editor, add:
BotAPI::sendMessage([ 'chat_id' => $chatId, 'text' => "An error occurred. Please try again or contact support.", 'parse_mode' => 'HTML' ]);
Add Special Command (Webhook Updates
#
):Command:
#
Auto Answer: None
Wait for Answer: Disabled
Help: “Processes all Telegram webhook updates.”
In the code editor, add:
if ($updateType === 'callback_query') { BotAPI::answerCallbackQuery([ 'callback_query_id' => $update['callback_query']['id'], 'text' => "Received your callback!", 'show_alert' => false ]); } elseif ($updateType === 'chat_member') { BotAPI::sendMessage([ 'chat_id' => $chatId, 'text' => "A chat member status changed!", 'parse_mode' => 'HTML' ]); }
Add Special Command (Webhook Message Updates
##
):Command:
##
Auto Answer: None
Wait for Answer: Disabled
Help: “Processes message-related webhook updates.”
In the code editor, add:
if ($updateType === 'message' && isset($update['message']['text'])) { BotAPI::sendMessage([ 'chat_id' => $chatId, 'text' => "Received your message: " . $update['message']['text'], 'parse_mode' => 'HTML' ]); }
This setup ensures the /start
command prompts for a name, the default *
catches unrecognized inputs, ((
runs before commands, ))
runs after, !!
handles errors, #
processes all webhook updates, and ##
handles message-specific updates.
Tips for Command Management
Use Aliases for Regular Commands: Add aliases (e.g.,
/info
and/about
) to support multiple triggers for non-master commands. Avoid using*
,((
,))
,!!
,#
, or##
in aliases.Leverage Keyboards: Use custom keyboards to guide user input without complex coding.
Restrict Chat Types: Limit commands to specific chat types (e.g., Group) to prevent misuse.
Document with Help: Use the Help field to describe each command’s purpose for easier management.
Configure
*
Carefully: Create separate*
commands for each role (*
,((
,))
,!!
,#
,##
) in the Command field to avoid conflicts.Test
*
Behavior: Test with valid, invalid, error-inducing, and various webhook updates to verify that each*
configuration triggers as expected.Optimize
#
and##
: Use#
for broad update processing (e.g., analytics) and##
for message-specific tasks to optimize performance. Ensure#
logic is efficient, as it runs for every update.Error Handling: Make the
!!
*
command user-friendly and log errors for debugging (e.g., send error details to a private admin chat).
This system empowers you to control your bot’s behavior, from simple auto-answers to advanced PHP logic. The *
master command with *
, ((
, ))
, !!
, #
, and ##
configurations ensures robust handling of all scenarios, making your bot reliable and user-friendly.
Last updated