While developing Discord bots or running scripts that access the Discord API, you might encounter an unfamiliar error code: 40333. The accompanying message says internal network error, which at first glance suggests a server-side issue at Discord. However, this is often a client-side configuration issue, specifically related to how your bot identifies itself.
In this article, we'll explain what this error really means and how to resolve it, including a workaround using Cloudflare Workers as a proxy.
The Error
When sending a request to the Discord API, you may receive a JSON response like this:
{
"message": "internal network error",
"code": 40333
}
Although "internal network error" sounds like a Discord outage, it is usually not a service-wide problem.
Cause: Cloudflare User-Agent Blocking
The reality of this error is a block by Cloudflare, which sits in front of Discord's infrastructure.
Previously, Cloudflare would return an HTML page (like "Access Denied"), but due to recent configuration changes at Discord, it now returns this JSON error instead.
Why get blocked?
The primary cause is the User-Agent (UA) header in your request. Discord's API security measures may block requests that masquerade as standard web browsers (like Chrome or Safari) when accessing Bot endpoints.
According to reports on GitHub, this can be reproduced by sending a curl request that includes a full browser User-Agent string:
# Example of a blocked request (using a browser User-Agent)
curl 'https://canary.discord.com/api/v9/channels/...' \
-H 'authority: canary.discord.com' \
-H 'authorization: Bot ...' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ... Chrome/108.0.5359.215 ...'
Developers sometimes add browser UAs to their bots to avoid generic web scrapers blocks, but for the Discord API, this practice often triggers the block you are trying to avoid.
Attempted Solution: Cloudflare Workers (Failed)
A common strategy to bypass IP restrictions is to use Cloudflare Workers as a proxy. However, we have found that this method often fails to resolve the issue.
Requests originating from Cloudflare Workers naturally come from Cloudflare's IP ranges. It appears that Discord (which also uses Cloudflare) may have configurations that flag direct requests from Cloudflare Workers or filter "Cloudflare-to-Cloudflare" traffic.
In practice, even when properly setting the User-Agent within a Worker and forwarding the request, the API often continues to return the 40333 error.
Similarly, requests from Google Apps Script (GAS) are frequently blocked due to the poor reputation of their shared IP addresses.
Current Conclusion
Unfortunately, there is no "silver bullet" to reliably bypass this issue using free serverless environments like GAS or Cloudflare Workers.
If you persist in seeing the 40333 error, you will likely need to change your hosting strategy:
- Use a VPS with a Static IP: Running your bot on a VPS (like AWS EC2, DigitalOcean, etc.) with a clean IP address is the most reliable solution.
- Host Locally: Running the bot from a home server or local PC usually works, as residential ISP IPs are less likely to be aggressively blocked than data center IPs.
- Use Residential Proxies: If you must run in a cloud environment that is blocked, you may need to route traffic through a trusted residential proxy service.
The idea that "proxying through Cloudflare Workers fixes IP issues" no longer seems to hold true for the Discord API.
Summary
- Error code 40333 with internal network error is a block by Cloudflare/Discord.
- Fixing the User-Agent alone may not be enough.
- Cloudflare Workers and GAS are also likely to be blocked.
- Reliable access requires moving to a hosting environment with a trusted IP address.
References
- Misleading API response for Cloudflare blocked requests · Issue #6473 · discord/discord-api-docs https://github.com/discord/discord-api-docs/issues/6473