Problem
I want to write a datetime.datetime object to a file, because my bot is down over night and I need it to check through all messages from that point of time until current messages but I found no solution how I could do this. The File Type doesn't matter as long as I can write the datetime.datetime object to it and can read it from it (but I would prefer JSON as I already got a system for writing, reading,... for this).
Tried
I tried to write it as raw datetime.datetime to a JSON File and tried to write it as raw datetime.datetime to a txt File with .write() which both didn't work because they don't accept that type.
Current code
At shutdown of the bot:
async for message in channel.history(limit=1):
lastmsg = message.created_at
jsonhandle.update("last_message", lastmsg, "lastmsg")
Called with on_ready:
last_message = jsonhandle.get("last_message", "lastmsg")
chistory = await channel.history(after=last_message).flatten()