因此,我正在尝试创建一个机器人,它允许您检索用户在特定通道中发送的消息数量。我知道channel.history()是一个东西,但我不确定是否可以将日期指定为参数。有没有一种方法可以统计用户在给定日期后在特定渠道发送的消息数量?
发布于 2021-03-05 05:22:53
我的答案基于this文档。您可以在那里找到许多discord.py库的详细信息。
是的,channel.history有一个after参数。它接受一个datetime对象。下面是一个简单的例子:
import datetime
# Get yesterdays date.
yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
counter = 0
# Make sure `limit` is set to None otherwise not all messages will be fetched.
async for message in channel.history(limit=None, after=yesterday):
if message.author = some_user:
counter += 1要小心,这段代码可能不能完全工作,不要只是复制和粘贴它。试着理解它在做什么。祝你的编码之旅好运!
https://stackoverflow.com/questions/66481517
复制相似问题