search_global()

async 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 (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.

Returns:

Generator – A generator yielding Message objects.

Example

from hydrogram import enums

# Search for "hydrogram". Get the first 50 results
async for message in app.search_global("hydrogram", 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)