Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error (403) when using UrlFetchApp to address an endpoint from https://discord.com

Discord recently announced that they move their API from discordapp.com to discord.com.

I'm in the midst of rewriting some code of mine (Google Apps Script project) to account for that, but I'm running into the problem of not being able to access the discord.com-endpoints, e.g.:

function example(){
  var headers =
  {
    "Authorization": "Bot AbCdEfG123",
    "Accept": "*/*"
  };
  var options =
  {
    "method": "GET",
    "headers": headers,
  };
  var response = UrlFetchApp.fetch("https://discord.com/api/guilds/"+GUILD_ID+"/members/"+MEMBER_ID, options);
}

even though using the old discordapp.com works perfectly fine. Using discord.com results in a 403 error, with error code 1020.

Further investigation:

  • Performing the same requests (against discord.com) via Postman or curl is successful, so it looks like the problem lies with UrlFetchApp
  • By adding "Accept": "*/*" to the headers, I found out that the error comes from Cloudflare, along with the message Please enable cookies.
  • Adding a User-Agent to the headers, e.g. "User-Agent": "MyBot/1.0" doesn't change anything

I have no idea how to deal with this and I'm wondering if anyone else has encountered this issue. I'm grateful for any help.

edit:

Here's the requested documentation:

  • Discord: https://discord.com/developers/docs/reference
  • UrlFetchApp: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app

The curl code that works is

curl -H "Authorization: Bot [...]" "https://discord.com/api/guilds/[...]/members/[...]"

with an ellipsis [...] representing the token or IDs

edit 2:

Google Apps Script uses the following unmodifiable user-agent:

Mozilla/5.0 (compatible; Google-Apps-Script; beanserver; +https://script.google.com; id: [...])

Even if I take only the Mozilla part into my curl command, i.e.

curl -H "Authorization: Bot [...]" -H "user-agent: Mozilla" "https://discord.com/api/guilds/[...]/members/[...]"

I get the same 1020 error code.

like image 856
PiFlavour Avatar asked Dec 21 '25 00:12

PiFlavour


1 Answers

You need to set the user agent per this format https://discord.com/developers/docs/reference#user-agent

User-Agent: DiscordBot ($url, $versionNumber)
like image 88
qaisjp Avatar answered Dec 24 '25 05:12

qaisjp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!