search_public_messages_by_tag()#

Client.search_public_messages_by_tag()#

Searches for public channel posts containing the given hashtag or cashtag. For optimal performance, the number of returned messages is chosen by Telegram Server and can be smaller than the specified limit.

If you want to get the posts count only, see count_public_messages_by_tag().

Usable by Users Bots
Parameters:
  • tag (str, optional) – Hashtag or cashtag to search for.

  • offset_id (int, optional) – Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results.

  • offset_date (datetime, optional) – Pass a date as offset to retrieve only older messages starting from that date.

  • limit (int, optional) – The maximum number of messages to be returned. By default, no limit is applied and all posts are returned.

Returns:

Generator – A generator yielding Message objects.

Example

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