From ed1bcb509f791a6b8e60cec77289c339c1fc21e4 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 29 Nov 2018 14:21:49 +0100 Subject: [PATCH] Use InputMessageReplyTo in get_reply_message This lets bots access to messages other bots sent through replies. --- telethon/tl/custom/message.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/telethon/tl/custom/message.py b/telethon/tl/custom/message.py index 9d4ee1ff..7e25018b 100644 --- a/telethon/tl/custom/message.py +++ b/telethon/tl/custom/message.py @@ -506,10 +506,21 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC): if not self.reply_to_msg_id: return None + # Bots cannot access other bots' messages by their ID. + # However they can access them through replies... self._reply_message = await self._client.get_messages( await self.get_input_chat() if self.is_channel else None, - ids=self.reply_to_msg_id + ids=types.InputMessageReplyTo(self.id) ) + if not self._reply_message: + # ...unless the current message got deleted. + # + # If that's the case, give it a second chance accessing + # directly by its ID. + self._reply_message = await self._client.get_messages( + self._input_chat if self.is_channel else None, + ids=self.reply_to_msg_id + ) return self._reply_message