Skip to content

The bot responds to commands for other bots written as /command@botname #2476

@Allnorm

Description

@Allnorm

When using pyTelegramBotAPI, we can register a command using the decorator @bot.message_handler(commands=['help']). Let's say our bot has a username @example_bot, and this handler responds to the commands /help, /help@example_bot, which is correct. However, it also responds to the command /help@another_bot, which is incorrect.

Image
Image

Currently, the boilerplate code below is used to solve the problem, but it is obvious that it should be solved at the API level.

@bot.message_handler(commands=['help'])
def help_msg(message):
    if not bot_name_checker(message):
        return

def bot_name_checker(message):

    cmd_text = message.text.split()[0]

    if f"@{utils.bot.get_me().username}" in cmd_text or not "@" in cmd_text:
        return True
    else:
        return False

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions