Get telegram channel messages after an specific id with telethon

1707 views telethon
1

I want to get a specific channel posts after an id (ex. 1245). I write this code:

# After connection to session in cli variable
last_post = cli(
                GetHistoryRequest(
                    peer=entity,
                    limit=100,
                    offset_date=None,
                    add_offset=0,
                    hash=0
                )
            )

But this gives me the 100 last message. Even with the max_id argument passed to the GetHistoryRequest, I get the messages from the earlier message to older ones. How can I get messages with opposite order?

answered question

1 Answer

8

You must read the doc first and then ask your question. You can do it simply with the iter_messages argument as follow:

next_post = cli.iter_messages(
                entity,
                limit=5,
                min_id=your_post_id,
                reverse=True
            )

with the reverse argument you can get the posts with the reverse order.

posted this

Have an answer?

JD

Please login first before posting an answer.