Skip to main content

Client

class pyromod.listen.Client​

Bases: pyrogram.Client

async method listen​

async listen(filters: Filter | None = None, listener_type: ListenerTypes = ListenerTypes.MESSAGE, timeout: int | None = None, unallowed_click_alert: bool = True, chat_id: int | None = None, user_id: int | None = None, message_id: int | None = None, inline_message_id: str | None = None)

Listen for a message, callback query, etc.

Parameters​

ParameterTypeDescription
filterspyrogram.filters.Filter or NoneA filter to check the incoming message against.
listener_typepyromod.types.ListenerTypesThe type of listener to listen for.
timeoutint or NoneThe maximum amount of time to wait for a message.
unallowed_click_alertboolWhether to alert the user if they click a button that doesn’t match the filters.
chat_idint or NoneThe chat ID to listen for.
user_idint or NoneThe user ID to listen for.
message_idint or NoneThe message ID to listen for.
inline_message_idstr or NoneThe inline message ID to listen for.

Raises​

ExceptionDescription
pyromod.exceptions.ListenerStoppedIf the listener was stopped.
pyromod.exceptions.ListenerTimeoutIf the listener timed out.

Returns​

The message that was listened for. If the listener type is ListenerTypes.MESSAGE, then a pyrogram.types.Message object is returned. If the listener type is ListenerTypes.CALLBACK_QUERY, then a pyrogram.types.CallbackQuery object is returned.

async method ask​

async ask(chat_id: int, text: str, filters: Filter | None = None, listener_type: ListenerTypes = ListenerTypes.MESSAGE, timeout: int | None = None, unallowed_click_alert: bool = True, user_id: int | None = None, message_id: int | None = None, inline_message_id: str | None = None, \*args, \*\*kwargs)

Send a message and calls Client.listen to wait for a response.

Parameters​

ParameterTypeDescription
chat_idintThe chat ID to send the message to. It will also be used to listen for a response.
textstrThe text of the message to send.
filterspyrogram.filters.Filter or NoneA filter to check the incoming message against.
listener_typepyromod.types.ListenerTypesThe type of listener to listen for.
timeoutint or NoneThe maximum amount of time to wait for a message.
unallowed_click_alertboolWhether to alert the user if they click a button that doesn’t match the filters.
user_idint or NoneThe user ID to listen for.
message_idint or NoneThe message ID to listen for.
inline_message_idstr or NoneThe inline message ID to listen for.
\*args
\*\*kwargs

Returns​

The message that was listened for. In the attribute request you can find the message that was sent. If the listener type is ListenerTypes.MESSAGE, then a pyrogram.types.Message object is returned. If the listener type is ListenerTypes.CALLBACK_QUERY, then a pyrogram.types.CallbackQuery object is returned.

method get_matching_listener​

get_matching_listener(pattern: Identifier, listener_type: ListenerTypes)

Get a listener that matches the given pattern.

Parameters​

ParameterTypeDescription
patternpyromod.types.Identifier
listener_typepyromod.types.ListenerTypes

Returns​

The listener that matches the given pattern or None.

method get_many_matching_listeners​

get_many_matching_listeners(pattern: Identifier, listener_type: ListenerTypes)

Get all listeners that match the given pattern.

Parameters​

ParameterTypeDescription
patternpyromod.types.Identifier
listener_typepyromod.types.ListenerTypes

Returns​

All listeners that match the given pattern.

method remove_listener​

remove_listener(listener: Listener)

Remove a listener.

Parameters​

ParameterTypeDescription
listenerpyromod.types.Listener

Returns​

None

method stop_listening​

stop_listening(listener_type: ListenerTypes = ListenerTypes.MESSAGE, chat_id: int | None = None, user_id: int | None = None, message_id: int | None = None, inline_message_id: str | None = None)

Stop listening for a message, callback query, etc.

Parameters​

ParameterTypeDescription
listener_typepyromod.types.ListenerTypes
chat_idint or NoneThe chat ID to stop listening for.
user_idint or NoneThe user ID to stop listening for.
message_idint or NoneThe message ID to stop listening for.
inline_message_idstr or NoneThe inline message ID to stop listening for.

Returns​

None

dict listeners​

listeners: dict[ListenerTypes, list[Listener]]