Skip to content

Hitting API rate limit with a small, command-centric bot that should not be making anywhere near 50 requests a second #5030

@AzazelWormwood

Description

@AzazelWormwood

Description

https://discord.com/developers/applications/641672044076990470/
https://github.com/AzazelWormwood/Jax/blob/main/litbot.py

This bot is a small nextcord.py based bot running off a sparkedhost.us server, and it is returning a 429 Too Many Requests (error code 0) error and temporarily blocking access to the API. The bot itself doesn't do anything on its own; it only responds to commands. I am not sure what would cause it to make enough requests that it hits the rate limit. I have three theories, but none seem particularly likely:

--The bot is checking on_message() too fast. This doesn't seem likely, since the server rarely gets 50 messages in a day, let alone a second.
--This is a result of yesterday's massive command usage. This seems unlikely because while there were ~10 commands used in succession, each requires a user response, limiting the rate to 1 command a second or slower.
--The sparkedhost.us server is refreshing too frequently, resulting in many unnecessary hits to the API. This seems the most probable, but even this seems unlikely, since it seems the server only refreshes every minute or so and there's nothing in the bot's source code that should be making that many requests anyway.

Steps to Reproduce

Traceback (most recent call last):
File "/home/container/litbot.py", line 393, in
bot.run(discord_API)
File "/home/container/.local/lib/python3.9/site-packages/nextcord/client.py", line 753, in run
return future.result()
File "/home/container/.local/lib/python3.9/site-packages/nextcord/client.py", line 732, in runner
await self.start(*args, **kwargs)
File "/home/container/.local/lib/python3.9/site-packages/nextcord/client.py", line 695, in start
await self.login(token)
File "/home/container/.local/lib/python3.9/site-packages/nextcord/client.py", line 563, in login
data = await self.http.static_login(token.strip())
File "/home/container/.local/lib/python3.9/site-packages/nextcord/http.py", line 382, in static_login
data = await self.request(Route('GET', '/users/@me'))
File "/home/container/.local/lib/python3.9/site-packages/nextcord/http.py", line 299, in request
raise HTTPException(response, data)
nextcord.errors.HTTPException: 429 Too Many Requests (error code: 0): You are being blocked from accessing our API temporarily due to exceeding our rate limits frequently. Please read our docs at https://discord.com/developers/docs/topics/rate-limits to prevent this moving forward.

Expected Behavior

The bot should successfully access the API with no issues

Current Behavior

The bot is temporarily banned due to rate limiting

Screenshots/Videos

No response

Client and System Information

I am running the bot on Python 3.9.10, nextcord.py, out of a sparkedhost.us linux-based server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions