From 6a5469edaf026a75b8b715d218439bbe60f84b43 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 30 Aug 2020 10:57:31 +0200 Subject: [PATCH] Don't attempt to retrieve chat attributes from empty messages Fixes #479 --- pyrogram/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyrogram/utils.py b/pyrogram/utils.py index 89ee7f6c..807d98a0 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -167,8 +167,17 @@ async def parse_messages(client, messages: "raw.types.messages.Messages", replie reply_message_ids = [i[0] for i in filter(lambda x: x[1] is not None, messages_with_replies.items())] if reply_message_ids: + # We need a chat id, but some messages might be empty (no chat attribute available) + # Scan until we find a message with a chat available (there must be one, because we are fetching replies) + for m in parsed_messages: + if m.chat: + chat_id = m.chat.id + break + else: + chat_id = 0 + reply_messages = await client.get_messages( - parsed_messages[0].chat.id, + chat_id, reply_to_message_ids=reply_message_ids, replies=replies - 1 )