1

我使用 Telethon 在电报上向我的联系人发送了多条消息,但我没有使用此事件来知道它们是否被直接阅读所以我想检查我的消息是否被阅读或没有使用其他方法


@client.on(events.MessageRead)
async def handler(event):
    # Log when someone reads your messages
    print('Someone has read all your messages until', event.max_id)

我阅读了完整的文档,但我找不到答案,是否知道消息是否已被读取或不使用它的 id 作为示例?cz 即使我调用 get_dialogs() 函数,它也会给我最后一条消息的 ID,而不是用户最后一次阅读的消息作为此处给出的评论

4

1 回答 1

2

获取Dialog您发送messageusing的位置GetPeerDialogsRequest(),然后如果该read_outbox_max_id属性等于或高于message.id,则消息已被读取。

chat = 'INSERT_CHAT'
msg_id = (await client.send_message(chat, 'YOUR_TEXT')).id

# get the Dialog where you sent the message
result = await client(functions.messages.GetPeerDialogsRequest(
        peers=[chat]
    ))
# check if the message has been read    
if result.dialogs[0].read_outbox_max_id >= msg_id:
    print('the message has been read')
else:
    print('the message has not been read yet')
于 2021-04-08T21:08:06.653 回答