Discord.js: Accessing Discord API gives a 403 response

Created on 15 Aug 2020  Â·  5Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible: Whenever I try to launch my Discord bot with any file from the webpack branch, it doesn't work. I always receive a 403 response when the bot tries to connect to https://discord.com/api/v7/gateway/bot.

The only way to connect is changing the API link to discordapp.com, which will be deprecated at November 7th (as said in an official message on Discord API's server, #announcements channel). Changing the API version to 6 gives the same problem.

Further details:

  • discord.js version: discord.master.min and discord.12.3.0.min
  • Node.js version: v12.16.1
  • Operating system: Windows 10, version 10.0.18362
  • Priority this issue should have – please be realistic and elaborate if possible: Not sure what priority it could be at the moment. If I can't access the API with discordapp.com, I'd say "high"?

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none

  • [X] I have also tested the issue on latest master, commit hash: f183cee9d343957a9c407498ecb24ad6d6b4739d

Discord bug bug

Most helpful comment

This seems to be outside of our control and you probably want to raise this issue to Discord.

The first thing the browser does is a CORS preflight request to check that it is allowed to access the requested resource (here: GET /gateway/bot). This request successfully makes it through CloudFlare to Discord, which then sends back the appropriate headers stating that the requested resource may be accessed.

After that the browser makes the actual request, which however never reaches Discord and instead is being rejected by CloudFlare stating that the access was denied (relevant bit of the response: <p>This website is using a security service to protect itself from online attacks.</p>)

As you already discovered, this does not seem to be an issue on https://discordapp.com, which suggests that there is something incorrectly configured on CloudFlare (by Discord?) regarding https://discord.com.

All 5 comments

This seems to be outside of our control and you probably want to raise this issue to Discord.

The first thing the browser does is a CORS preflight request to check that it is allowed to access the requested resource (here: GET /gateway/bot). This request successfully makes it through CloudFlare to Discord, which then sends back the appropriate headers stating that the requested resource may be accessed.

After that the browser makes the actual request, which however never reaches Discord and instead is being rejected by CloudFlare stating that the access was denied (relevant bit of the response: <p>This website is using a security service to protect itself from online attacks.</p>)

As you already discovered, this does not seem to be an issue on https://discordapp.com, which suggests that there is something incorrectly configured on CloudFlare (by Discord?) regarding https://discord.com.

I am getting this error as well when attempting to do this with WSL2. Has a solution been found?

iirc Discord said that the issues with discord.js in the browser are because it isn't setting the user-agent correctly

Latest: Web builds won't be continued and are discouraged by discord itself.

Was this page helpful?
0 / 5 - 0 ratings