Python 如何使用telethon仅从聊天中获取未读消息?

Python 如何使用telethon仅从聊天中获取未读消息?,python,telethon,Python,Telethon,我有client.get_messages(dialog.entity)但它只返回没有“read/unread标记”的消息。。。 那么,我怎样才能只收到未读的新邮件呢? 有人知道吗 每个对话框都有未读计数 x = [[d.unread_count, d.title] for d in client.get_dialogs() if not getattr(d.entity, 'is_private', False) and d.unread_count != 0] 除了接受的答案外,还可以只获

我有
client.get_messages(dialog.entity)
但它只返回没有“read/unread标记”的消息。。。 那么,我怎样才能只收到未读的新邮件呢?
有人知道吗 每个对话框都有
未读计数

x = [[d.unread_count, d.title] for d in client.get_dialogs() if not getattr(d.entity, 'is_private', False) and d.unread_count != 0]

除了接受的答案外,还可以只获取您感兴趣的对话框,这些对话框也可以用于对整个文件夹进行操作

要从
'username'
获取未读邮件的数量,请执行以下操作:

从telethon.sync导入客户端
从telethon导入函数、类型
以电报客户端(名称、api\u id、api\u哈希)作为客户端:
结果=客户端(functions.messages.GetPeerDialogsRequest(
对等方=['username']
))
打印(结果。对话框[0]。未读计数)
请注意,
peers
可能是一个列表,因此您可以一次获取多个。请注意,该对话框包含更多信息,例如“已读取到哪个ID”

x = [[d.unread_count, d.title] for d in client.get_dialogs() if not getattr(d.entity, 'megagroup', False) and d.unread_count != 0]