search_global()

Client.search_global()

Search messages globally from all of your chats.

If you want to get the messages count only, see search_global_count().

Note

Due to server-side limitations, you can only get up to around ~10,000 messages and each message retrieved will not have any reply_to_message field.

Usable by Users Bots
Parameters:
  • query (``str``, *optional*) – Text query string. Use “@” to search for mentions.

  • filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*) – Pass a filter in order to search for specific kind of messages only. Defaults to any message (no filter).

  • limit (``int``, *optional*) – Limits the number of messages to be retrieved. By default, no limit is applied and all messages are returned.

  • chat_list (``int``, *optional*) – Chat list in which to search messages; Only Main (0) and Archive (1) chat lists are supported. Defaults to (0) Main chat list.

  • chat_type_filter (:obj:`~pyrogram.enums.ChatType`, *optional*) – Additional filter for type of the chat (PRIVATE, GROUP, CHANNEL) of the searched messages; pass None to search for messages in all chats.

  • offset_date (:py:obj:`~datetime.datetime`, *optional*) – The date starting from which the dialogs need to be fetched. Use 0 or any date in the future to get results from the last dialog.

  • offset_message_id (``int``, *optional*) – The message identifier of the last message in the last found dialog, or 0 for the first request.

Returns:

``Generator`` (A generator yielding Message objects.)

Example

from pyrogram import enums

# Search for "pyrogram". Get the first 50 results
async for message in app.search_global("pyrogram", limit=50):
    print(message.text)

# Search for recent photos from Global. Get the first 20 results
async for message in app.search_global(filter=enums.MessagesFilter.PHOTO, limit=20):
    print(message.photo)