Skip to content

Commit 6a5469e

Browse files
committed
Don't attempt to retrieve chat attributes from empty messages
Fixes #479
1 parent ecdba6b commit 6a5469e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pyrogram/utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,17 @@ async def parse_messages(client, messages: "raw.types.messages.Messages", replie
167167
reply_message_ids = [i[0] for i in filter(lambda x: x[1] is not None, messages_with_replies.items())]
168168

169169
if reply_message_ids:
170+
# We need a chat id, but some messages might be empty (no chat attribute available)
171+
# Scan until we find a message with a chat available (there must be one, because we are fetching replies)
172+
for m in parsed_messages:
173+
if m.chat:
174+
chat_id = m.chat.id
175+
break
176+
else:
177+
chat_id = 0
178+
170179
reply_messages = await client.get_messages(
171-
parsed_messages[0].chat.id,
180+
chat_id,
172181
reply_to_message_ids=reply_message_ids,
173182
replies=replies - 1
174183
)

0 commit comments

Comments
 (0)