search_posts()

async Client.search_posts()

Search public posts by hashtag or by text.

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

Usable by Users Bots
Parameters:
  • hashtag (str, optional) – Hashtag to search for, with or without the leading “#”.

  • query (str, optional) – Text to search for instead of a hashtag. Searching by text requires a Premium account; Telegram answers [403 PREMIUM_ACCOUNT_REQUIRED] otherwise.

  • limit (int, optional) – Limits the number of posts to be retrieved. By default, no limit is applied and all posts are returned.

Returns:

Generator – A generator yielding Message objects.

Raises:

ValueError – In case neither hashtag nor query is given.

Example

async for message in app.search_posts("wzgram"):
    print(message.text)