Answer the question
In order to leave comments, you need to log in
How to get messages for the last few hours?
Is it possible to pull out the last messages in a few hours from the channel by force or do I need to drag the database?
Answer the question
In order to leave comments, you need to log in
async for ... in history(...)
: https://discordpy.readthedocs.io/en/stable/api.htm...
counter = 0
async for message in channel.history(limit=200):
if message.author == client.user:
counter += 1
messages = await channel.history(limit=123).flatten()
# messages is now a list of Message...
from datetime import datetime, timedelta
# ...
async for message in channel.history(
limit=None, # If None, retrieves every message in the channel. Note, however, that this would make it a slow operation.
after=datetime.utcnow()-timedelta(hours=2) # If a date is provided it must be a timezone-naive datetime representing UTC time. (https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow)
):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question