Search code examples
pythonbotstelegrampyrogram

pyrogram - Filter commands addressed to the bot


If I filter a command using something like filters.command(["my_command"], in groups the bot gets notified when I execute the command /my_command, but if I address it to the bot (e.g. /my_command@MyBot) it won't get notified.

How can I modify the filter to get notified in both cases (independently on the bot name)?

Thanks


Solution

  • use regex

    with app:
        bot_username = app.get_me().username
    
    @app.on_message( filters.regex(f'^/my_command($|@{bot_username}$)') )
    def handler( client, message ):
        pass