So your bot is getting hit with a rate limit error code.
API Rate Limits
If a rate limit is exceeded (currently, 50 requests per second), the API will return a HTTP 429 response code. The limit for invalid requests is currently 10,000 per 10 minutes. However, if your bot gets temporarily CloudFlare banned from the API, it is most likely not a global rate limit issue and is more likely a spike in errors that were not properly handled.
First thing we want to note is that we, under very few circumstances, raise the global rate limit on applications. The good news is there are available workarounds that we encourage developers to look into when building their apps.
We also want to mention that interaction endpoints are not bound to the rate limit. So migrating functionality to application commands where possible could be another solution. Definitely take a look at our docs on that here, or documentation for the library of your choice.
Gateway Rate Limits
To send data to/from Discord, your application connects to a websocket. Sharding is generally a best practice for applications especially as they continue to grow and scale on Discord. It’s a sure-fire way of working not quite around.. but within our API rate limits. Sharding opens multiple websockets so data can be exchanged across all of these connections rather than overloading one.
shard_id = (guild_id >> 22) % num_shards
Traffic from guilds/servers will be routed to a shard (open websocket) and their requests will run in parallel to each other to stay under the global rate limit. Think of sharding as splitting your bot into multiple instances of itself. It’s entirely user-controlled and is only made simpler by your library of choice!
With regard to large bot sharding and an increased global rate limit, these are services we can only offer to bots that are operating in 150,000 servers or more. You can learn more about how these requests work in our documentation: https://discord.com/developers/docs/topics/gateway#sharding-for-very-large-bots
You can read more about how to fine tune and configure shards here.