Handle cases when Message.reply_to is MessageReplyStoryHeader

This commit is contained in:
UZQueen 2025-06-07 05:27:29 -05:00 committed by GitHub
parent 7b00d2f510
commit 31e8ceeecc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -96,7 +96,7 @@ class Message(ChatGetter, SenderGetter, TLObject):
The ID of the bot used to send this message
through its inline mode (e.g. "via @like").
reply_to (:tl:`MessageReplyHeader`):
reply_to (:tl:`MessageReplyHeader` | :tl:`MessageReplyStoryHeader`):
The original reply header if this message is replying to another.
date (`datetime`):
@ -379,10 +379,11 @@ class Message(ChatGetter, SenderGetter, TLObject):
@property
def is_reply(self):
"""
`True` if the message is a reply to some other message.
`True` if the message is a reply to some other message or story.
Remember that you can access the ID of the message
this one is replying to through `reply_to.reply_to_msg_id`,
Remember that if the replied-to is a message,
you can access the ID of the message this one is
replying to through `reply_to.reply_to_msg_id`,
and the `Message` object with `get_reply_message()`.
"""
return self.reply_to is not None
@ -671,7 +672,11 @@ class Message(ChatGetter, SenderGetter, TLObject):
Returns the message ID this message is replying to, if any.
This is equivalent to accessing ``.reply_to.reply_to_msg_id``.
"""
return self.reply_to.reply_to_msg_id if self.reply_to else None
return (
self.reply_to.reply_to_msg_id
if isinstance(self.reply_to, types.MessageReplyHeader)
else None
)
@property
def to_id(self):
@ -737,7 +742,7 @@ class Message(ChatGetter, SenderGetter, TLObject):
The result will be cached after its first use.
"""
if self._reply_message is None and self._client:
if not self.reply_to:
if not isinstance(self.reply_to, types.MessageReplyHeader):
return None
# Bots cannot access other bots' messages by their ID.