E
E
estry2021-09-23 14:46:38
Python
estry, 2021-09-23 14:46:38

How to call multiple pyrogram decarators in Python?

Hello.
I am implementing a task for telegram. Now we need to make sure that all the decorators that are in the code are called. In the current implementation, only the first one works. And it is necessary that all decorators suitable for the conditions work.
For example, here is the code:

api_id = 1219
api_hash = "8a57f29f598197d9efe9+3"

app = Client("D:/my_account", api_id, api_hash)


@app.on_message(filters.text & filters.outgoing)
def callback(client: app, message: Message):
    if 'smile' in message.text:
        msg = message.text.replace('smile', 'CENSORED')
        message.edit_text(msg)


@app.on_message(filters.text & filters.outgoing)
def callback(client: app, message: Message):
    for k in range(11):
        message.edit_text(str(k))


As you can see app.on_message is there twice. But only one works - the first one.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stefan, 2021-09-23
@MEDIOFF

So put the necessary actions into separate functions and run them from one handler, naturally only the first one works for you, since it matches first and no longer looks for

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question