My bot is supposed to fetch all the messages in a specific channel and time period and add them to a list. However, it constantly gets rate limited while it is fetching the messages.
for channel in ctx.guild.channels:
async for message in channel.history(limit=None, before=to_date, after=start_message, oldest_first=True):
await asyncio.sleep(0.3)
messages_to_mimic.append({
"content": messagecontent,
"attachments": attachments,
"author_name": display_name,
"author_avatar": avatar_url,
"channel_name": channel.name,
"original_channel_id": channel.id,
"timestamp": message.created_at,
"user_id": user_id,
"message_id": message.id
})
I was expecting the bot to fetch the messages as it intended, but instead it stops in the middle and spams “We have been rate limited!” in the terminal. I’ve tried adding a delay between getting each message, using parameters to make the message pool smaller, error handling rate limits, and limiting the message fetching to only the channels needed. None of these efforts worked.
Flash Flood is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5