不和谐 message.createdat
Discord py message.createdat
我想知道如何格式化以下内容:
async def sendmessage():
channel = client.get_channel(786258218925293629)
fetchMessages = await channel.history().find(lambda m: m.author.id == 627862713242222632)
print(fetched.created_at)
我的最终目标是检查消息是否在最近 30 分钟内发送,如果是,则删除消息。
我需要将其格式化为消息发送前的秒数。目前的输出是:
2020-12-13 20:19:24.414000
如有任何帮助,我们将不胜感激。
您可以通过从表示当前时间的日期时间对象中减去 created_at
日期时间对象来获得消息发送前的秒数。执行此操作的代码应如下所示:
import datetime # put this at the top of your code
...
async def sendmessage():
channel = client.get_channel(786258218925293629)
fetchMessages = await channel.history().find(lambda m: m.author.id == 627862713242222632)
# i'm not sure where the fetched variable is from so i'm assuming you just forgot to include that bit of code
msg_secs = (datetime.datetime.now() - fetched.created_at).total_seconds()
print(int(msg_secs))
API 参考资料:
datetime / timedelta object for datetime subtraction
我想知道如何格式化以下内容:
async def sendmessage():
channel = client.get_channel(786258218925293629)
fetchMessages = await channel.history().find(lambda m: m.author.id == 627862713242222632)
print(fetched.created_at)
我的最终目标是检查消息是否在最近 30 分钟内发送,如果是,则删除消息。
我需要将其格式化为消息发送前的秒数。目前的输出是: 2020-12-13 20:19:24.414000
如有任何帮助,我们将不胜感激。
您可以通过从表示当前时间的日期时间对象中减去 created_at
日期时间对象来获得消息发送前的秒数。执行此操作的代码应如下所示:
import datetime # put this at the top of your code
...
async def sendmessage():
channel = client.get_channel(786258218925293629)
fetchMessages = await channel.history().find(lambda m: m.author.id == 627862713242222632)
# i'm not sure where the fetched variable is from so i'm assuming you just forgot to include that bit of code
msg_secs = (datetime.datetime.now() - fetched.created_at).total_seconds()
print(int(msg_secs))
API 参考资料: datetime / timedelta object for datetime subtraction