add_handler()

Client.add_handler()

Register an update handler.

You can register multiple handlers, but at most one handler within a group will be used for a single update. To handle the same update more than once, register your handler using a different group id (lower group id == higher priority). This mechanism is explained in greater details at More on Updates.

Parameters
  • handler (Handler) – The handler to be registered.

  • group (int, optional) – The group identifier, defaults to 0.

Returns

tuple – A tuple consisting of (handler, group).

Example

from pyrogram import Client, MessageHandler

def dump(client, message):
    print(message)

app = Client("my_account")

app.add_handler(MessageHandler(dump))

app.run()