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 ofhashtagorquerymust be provided.Usable by Users Bots
- Parameters:
hashtag (
str, optional) – Hashtag to search for (without the `` At least one ofhashtagorquerymust be set.query (
str, optional) – Free-text search query. At least one ofhashtagorquerymust 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 (pass0to skip paid posts entirely).
- Yields:
Message– Matching channel post messages.- Raises:
raises ValueError: If neither
hashtagnorqueryis 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)