.logs_from() 操作的 after 属性的值应该如何格式化?

How should the value of the after attribute for the operation .logs_from() be formatted?

我正在尝试从我的机​​器人有权访问的所有渠道检索今天发送的所有消息的可迭代(如脚本 运行 那天)。

就目前而言,我一直在尝试使用 .logs_from()after 属性,但是我似乎无法让它按照我希望的方式运行:

import discord
import asyncio
import time

client = discord.Client()

today = time.strftime("%Y-%m-%d")

@client.event
async def on_ready():
    for i in client.get_all_channels():
        async for c in client.logs_from(i, after=today):
            print(c.content)

client.run(INSERT_SESSION_KEY)

运行 这似乎只是从我的机器人可以访问的频道输出所有消息的列表。我假设我输入的 after 值格式不正确,但文档仅说明:

after (Message or datetime) – The message or date after which all returned messages must be. If a date is provided it must be a timezone-naive datetime representing UTC time.

我的印象是我在做什么。

有谁能建议为 .logs_from() 声明 after 属性值的正确方法是什么?

感谢 https://whosebug.com/users/8360823/squaswin 的建议。 感谢 https://whosebug.com/users/131187/bill-bell 指出 UTC 时区差异。

使用 datetime 而不是 time 似乎符合要求。

见下文:

import discord
import asyncio
import datetime

client = discord.Client()

@client.event
async def on_ready():
    for i in client.get_all_channels():
        async for c in client.logs_from(i, after=date.today()):
            print(c.content)

client.run(INSERT_SESSION_KEY)

以上return是今天发送的所有消息。

要包含一天中的特定时间,请使用以下方法:

import discord
import asyncio
import datetime

client = discord.Client()

@client.event
async def on_ready():
    for i in client.get_all_channels():
        async for c in client.logs_from(i, after=datetime.now()):
            print(c.content)

client.run(INSERT_SESSION_KEY)

但是以上两个 return 当前时区,要获取 UTC 的当前日期,您可以使用以下内容:

import discord
import asyncio
import datetime

client = discord.Client()

@client.event
async def on_ready():
    for i in client.get_all_channels():
        async for c in client.logs_from(i, after=datetime.utcnow().date()):
            print(c.content)

client.run(INSERT_SESSION_KEY)