我想将 datetime.datetime 对象写入文件,因为我的机器人整夜停机,我需要它检查从该时间点到当前消息的所有消息,但我找不到解决方案如何做到这一点。文件类型并不重要,只要我可以向其中写入 datetime.datetime 对象并可以从中读取它(但我更喜欢 JSON,因为我已经有了一个用于写入、读取的系统,...为此)。
我尝试将其作为原始 datetime.datetime 写入 JSON 文件,并尝试将其作为原始 datetime.datetime 写入 txt 文件,但.write()两者都不起作用,因为它们不接受该类型。
机器人关闭时:
async for message in channel.history(limit=1):
lastmsg = message.created_at
jsonhandle.update("last_message", lastmsg, "lastmsg")
Run Code Online (Sandbox Code Playgroud)
调用方式on_ready:
last_message = jsonhandle.get("last_message", "lastmsg")
chistory = await channel.history(after=last_message).flatten()
Run Code Online (Sandbox Code Playgroud) Discord_slash适合任何刚接触 Discord_slash 的人,相当复杂,在我看来,这些文档有点奇怪且难以理解,因此这里有一个初学者指南,用于开始使用第三方 Discord.py 扩展。
要完全理解这一点,您还必须至少有一点不和谐的经验和Python的经验!