0

I want to be able to handle a command like this:

https://t.me/MyBot?start=aff_1234

How will I do it? I've tried this and it hasn't worked:

from pyrogram import Client, filters

# ......
# ......

c = Client("bot"...)
hd = MessageHandler(main_handler)
c.add_handler(hd)

# ......

async def main_handler(client, message):
    try:
        # when a new user connects as
        # https://t.me/MyBot?start=aff_1234
        # this will never get fired
        # why not?

        print("debug #1")
        if message.text.startswith('/start'):
          parts = message.text.split('=aff_')
          # ..............
CallMeStag
  • 5,467
  • 1
  • 7
  • 22
Kon
  • 33
  • 1
  • 5

1 Answers1

0

please read the pyrogram documentation to avoid mistakes

first of all, use app.on_message to handle message.

you can do that using regex

example:

from pyrogram import Client, filters
app = Client("bot", ...)

@app.on_message(filters.regex(r'^/start aff_(\d+)'))
def handler(client, message):
    number = message.matches[0].group(1)