简体   繁体   中英

How to get message replies from Telegram groups by API - Python

I am trying to fetch the replies to the messages in a channel. For example: if my post has 60 replies ("discussion" as mentioned in the app) in channel X (let's say 1555671526), I need to fetch all those 60 reply messages along with the original post.

As of now I'm trying:

# using get_messages
channel_id = 1555671526 # it is sample channel (random)
message = client.get_messages(channel_id)
reply = message.get_reply_message()
print(reply)

# using iter_messages
for m in client.iter_messages(c):
    print(m.get_reply_message())

I understand if there are no replies, get_reply_message will return None and it is returning None in both cases. However, I can see that there are replies to the post.

Can someone suggest to me how to fetch the reply messages?

Thanks in advance!

channel_id = 1555671526
replies = []
for message in client.iter_messages(channel_id):
    for reply in message.iter_replies():
        replies.append(reply)
print(replies)

You should also check whether the channel is public or private, as the bot must join private channels before it may fetch messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM