Closed hughbe closed 2 years ago
Thanks for the kind words.
Luckily, I can reproduce the issue. Telethon sees that it made a request for 100 messages but only 99 were returned. It then assumes "well, if I asked for 100 and there's only 99 left, I must have reached the end":
I have no idea why it's doing this. It's very unfortunate, because a fix will hinder all other "healthy" channels into making one more request than necessary to confirm if there are messages left.
So for what its worth, I was able to do something like the following:
max_id = 0
while True:
messages = await client.get_messages(CHANNEL, max_id=max_id)
if not messages:
break
for message in messages:
print(message.id, message.date)
max_id = messages[-1].id
Would this have the desired result, you think?
That's a workaround. But it's stupid the client has to do (something equivalent to) that. It might be a bug in Telegram itself.
Should I report it? If so, to whom?
I've talked about it in https://t.me/tdlibchat/57257 if you're interested. The above commit should fix the issue though, so I don't really care much more beyond that.
Here's another fun one someone else found:
offset_id 132002, limit 4 => we get msg 131999 & 131998
offset_id 132002, limit 3 => we get msg 131999
offset_id 132002, limit 2 => we get msg 132000
offset_id 132002, limit 1 => we get msg 132001
I got a similar issue which got me here.
I suddenly noticed that when reversed was applied, I could only get the first 100 messages, but if I removed reverse, then it would get all messages.
async for message in bot.iter_messages(event.chat_id, reverse=True,limit=None, offset_date=one_week_back):
print(message)
my solution was to add min_id so I skipped the first 2-3 MessageService where it says the group is created
async for message in bot.iter_messages(event.chat_id, reverse=True,limit=None, offset_date=one_week_back, min_id = 5):
print(message)
Posting it here in case it's useful. I got the idea to use min_id when I saw the behavior with limit.
Hi,
Firstly - thanks for producing such a robust library. Finding it very useful.
I've encountered some unusual behaviour with
client.iter_messages
.In the example below:
TelethonChat
iterates all the messages in theTelethonChat
channel - this is expected.SolovievLive
only iterates the first 99 messages in theSolovievLive
channel - this is unexpected (I know there are hundreds more messages on that channel).I can't quite explain why one channel works with
limit=None
and keeps iterating downwards, and the other doesn't!Checklist
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.Code that causes the issue