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 messagePlease 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.
Botand the space before the token in authorization header? - TheMasterBotis there, right where it belongs. - PiFlavourBot. Do edit your question code to make it clear that you useBotin the correct position. Also addAccept:headers in the code.Please enable cookies.would mean you're redirected from a error page to a html page. - TheMaster