From 11ef4ce3701457af6f51856797c11de14378d570 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 6 Sep 2018 15:41:04 +0200 Subject: [PATCH] Fix _document_by_attribute failing on empty media --- telethon/tl/custom/message.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/telethon/tl/custom/message.py b/telethon/tl/custom/message.py index 7ebc00a5..7f8771da 100644 --- a/telethon/tl/custom/message.py +++ b/telethon/tl/custom/message.py @@ -700,9 +700,12 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC): Helper method to return the document only if it has an attribute that's an instance of the given kind, and passes the condition. """ - for attr in self.document.attributes: - if isinstance(attr, kind): - if not condition or condition(self.document): - return self.document + doc = self.document + if doc: + for attr in doc.attributes: + if isinstance(attr, kind): + if not condition or condition(doc): + return doc + return None # endregion Private Methods