我需要有脚本才能读取电报频道的最后一条消息。如果该频道的最后一条消息是回复某件事,我想阅读该消息,最后一条消息的答案是什么。例如,这张图片上的突出显示的消息。
https://i.stack.imgur.com/cRSzS.jpg
我有这段代码可以读取最后一条消息,但是我不知道如何读取该消息,我知道我可以使用is_reply参数来知道最后一条消息是否是对某件事的答复,但是我不知道下一步该怎么做想法?
async def get_mess():
limit = 1
global new
async for message in client.iter_messages('Passive Lifestyle Forex Signals', limit):
new = message.text
whlie True:
get_mess()
我知道这不是最有效的方法,但这并不重要。任何想法如何编写此代码?如果您需要更具体的信息,我可以回答您。
答案 0 :(得分:0)
async def get_mess():
limit = 1
global new
async for message in client.iter_messages('Passive Lifestyle Forex Signals', limit):
new = message
if new.reply_to_msg_id:
yourtext = await new.get_reply_message()
whlie True:
get_mess()
答案 1 :(得分:0)
我建议使用get_messages
来获取最后一条消息,以便您也可以忽略该限制。然后,您需要检查该邮件是否在答复另一封邮件,如果是,请获取它。
async def get_mess():
global new
message = await client.get_messages('YOUR CHAT') # you can omit the limit
if message.is_reply:
new = await message.get_reply_message()
whlie True:
get_mess()