search_channel_posts()

Client.search_channel_posts()

Search posts across all public channels by hashtag or text query.

This method calls channels.searchPosts (TL Layer 207+). At least one of hashtag or query must be provided.

Usable by Users Bots

Parameters:
  • hashtag (str, optional) – Hashtag to search for (without the `` At least one of hashtag or query must be set.

  • query (str, optional) – Free-text search query. At least one of hashtag or query must be set.

  • limit (int, optional) – Maximum number of messages to return. Defaults to 0 (no limit — all results are fetched).

  • allow_paid_stars (int, optional) – Maximum amount of Stars the user agrees to spend to view pay-walled posts (pass 0 to skip paid posts entirely).

Yields:

Message – Matching channel post messages.

Raises:

raises ValueError: If neither hashtag nor query is provided.

Example

async for msg in app.search_channel_posts(hashtag="pyrogram"):
    print(msg.text)


async for msg in app.search_channel_posts(query="Telegram update", limit=50):
    print(msg.chat.title, msg.text)