I am attempting to retrieve an iterable of all messages sent today (as in the day that the script is run) from all channels that my bot has access to.
As it stands I have been attempting to use the after
attribute of .logs_from()
however I cannot seem to get this to act as I would like it to:
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)
Running this seems to just output a list of all messages from the channels my bot has access to. I'm assuming that I my input for the value of after
is not in the correct format, however the documentation merely states:
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.
Which I was under the impression I was doing.
Is anyone able to advise what the proper way to declare the value of the after
attribute for .logs_from()
is?
Thanks to https://stackoverflow.com/users/8360823/squaswin for the suggestion. Thanks to https://stackoverflow.com/users/131187/bill-bell for pointing out the UTC timezone differences.
Using
datetime
instead oftime
seems to work as required.See below:
The above returns all messages sent today.
To include a specific time of day, using the below works:
However both of these above return the current timezone, to get the current date in UTC, you can use the below: