MessageHandler

class pyrogram.handlers.MessageHandler

Bases: Handler

The Message handler class. Used to handle new messages. It is intended to be used with add_handler()

For a nicer way to register this handler, have a look at the on_message() decorator.

Parameters:
  • callback (Callable) – Pass a function that will be called when a new Message arrives. It takes (client, message) as positional arguments (look at the section below for a detailed description).

  • filters (Filters) – Pass one or more filters to allow only a subset of messages to be passed in your callback function.

Other Parameters:
  • client (Client) – The Client itself, useful when you want to call other API methods inside the message handler.

  • message (Message) – The received message.

async check_if_has_matching_listener(client, message)

Checks if the message has a matching listener.

Parameters:
  • client – The Client object to check with.

  • message – The Message object to check with.

Returns:

A tuple of whether the message has a matching listener and its filters does match with the Message and the matching listener.

async check(client, message)

Checks if the message has a matching listener or handler and its filters does match with the Message.

Parameters:
  • client – Client object to check with.

  • message – Message object to check with.

Returns:

Whether the message has a matching listener or handler and its filters does match with the Message.

async resolve_future_or_callback(client, message, *args)

Resolves the future or calls the callback of the listener if the message has a matching listener.

Parameters:
  • client – Client object to resolve or call with.

  • message – Message object to resolve or call with.

  • args – Arguments to call the callback with.

Returns:

None