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.
- 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.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 (
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.
- Returns:
Generator
– A generator yieldingMessage
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)