Decorators¶
While still being methods bound to the Client class, decorators are of a special kind and thus
deserve a dedicated page.
Decorators are able to register callback functions for handling updates in a much easier and cleaner way compared to
Handlers; they do so by instantiating the correct handler and calling
add_handler() automatically. All you need to do is adding the decorators on top of your
functions.
from pyrogram import Client
app = Client("my_account")
@app.on_message()
def log(client, message):
print(message)
app.run()
Index¶
Details¶
-
@pyrogram.Client.on_message¶ Decorator for handling messages.
This does the same thing as
add_handler()using theMessageHandler.- Parameters
filters (
Filters, optional) – Pass one or more filters to allow only a subset of messages to be passed in your function.group (
int, optional) – The group identifier, defaults to 0.
-
@pyrogram.Client.on_callback_query¶ Decorator for handling callback queries.
This does the same thing as
add_handler()using theCallbackQueryHandler.- Parameters
filters (
Filters, optional) – Pass one or more filters to allow only a subset of callback queries to be passed in your function.group (
int, optional) – The group identifier, defaults to 0.
-
@pyrogram.Client.on_inline_query¶ Decorator for handling inline queries.
This does the same thing as
add_handler()using theInlineQueryHandler.- Parameters
filters (
Filters, optional) – Pass one or more filters to allow only a subset of inline queries to be passed in your function.group (
int, optional) – The group identifier, defaults to 0.
-
@pyrogram.Client.on_chosen_inline_result¶ Decorator for handling chosen inline results.
This does the same thing as
add_handler()using theChosenInlineResult.- Parameters
filters (
Filters, optional) – Pass one or more filters to allow only a subset of chosen inline results to be passed in your function.group (
int, optional) – The group identifier, defaults to 0.
-
@pyrogram.Client.on_deleted_messages¶ Decorator for handling deleted messages.
This does the same thing as
add_handler()using theDeletedMessagesHandler.- Parameters
filters (
Filters, optional) – Pass one or more filters to allow only a subset of messages to be passed in your function.group (
int, optional) – The group identifier, defaults to 0.
-
@pyrogram.Client.on_user_status¶ Decorator for handling user status updates. This does the same thing as
add_handler()using theUserStatusHandler.- Parameters
filters (
Filters, optional) – Pass one or more filters to allow only a subset of UserStatus updated to be passed in your function.group (
int, optional) – The group identifier, defaults to 0.
-
@pyrogram.Client.on_poll¶ Decorator for handling poll updates.
This does the same thing as
add_handler()using thePollHandler.- Parameters
filters (
Filters, optional) – Pass one or more filters to allow only a subset of polls to be passed in your function.group (
int, optional) – The group identifier, defaults to 0.
-
@pyrogram.Client.on_disconnect¶ Decorator for handling disconnections.
This does the same thing as
add_handler()using theDisconnectHandler.
-
@pyrogram.Client.on_raw_update¶ Decorator for handling raw updates.
This does the same thing as
add_handler()using theRawUpdateHandler.- Parameters
group (
int, optional) – The group identifier, defaults to 0.