gpt4 book ai didi

python - Telethon Telegram 消息过滤器

转载 作者:行者123 更新时间:2023-12-05 06:30:57 25 4
gpt4 key购买 nike

我想获取今天发送的聊天中的所有消息。

import sys,datetime
from telethon import TelegramClient
api_id = 1234567
api_hash = "0986asdgshjfag"
client = TelegramClient('session_name', api_id, api_hash)
client.start()

dialogs = client.get_dialogs()
chat = client.get_input_entity('username')


filter = InputMessagesFilterEmpty()
result = client(SearchRequest(
peer=chat, # On which chat/conversation
q='', # What to search for
filter=filter, # Filter to use (maybe filter for media)
min_date=datetime.date.today(), # Minimum date
max_date=None, # Maximum date
offset_id=0, # ID of the message to use as offset
add_offset=0, # Additional offset
limit=5, # How many results
max_id=0, # Maximum message ID
min_id=0, # Minimum message ID
from_id=None, # Who must have sent the message (peer)
hash=0 # Special number to return nothing on no-change
))

for message in client.iter_messages(chat,filter=result):
print(message.message)

过滤器根本不起作用,我可以看到超过 5 条消息(整个聊天)并且它不关心时间。为什么?

最佳答案

您可以使用“message.date”。

如果您想从今天开始收到消息,您需要检查发送日期。这就像:

if datetime.datetime.now().strftime('%Y-%m-%d') == message.date.strftime('%Y-%m-%d')

关于python - Telethon Telegram 消息过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52003156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com