remove_handler()

Client.remove_handler()

Remove a previously-registered update handler.

Make sure to provide the right group where the handler was added in. You can use the return value of the add_handler() method, a tuple of (handler, group), and pass it directly.

Parameters:
  • handler (Handler) – The handler to be removed.

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

Example

from pyrogram import Client
from pyrogram.handlers import MessageHandler

async def hello(client, message):
    print(message)

app = Client("my_account")

handler = app.add_handler(MessageHandler(hello))

# Starred expression to unpack (handler, group)
app.remove_handler(*handler)

app.run()