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:
discord.com) via Postman or curl is successful, so it looks like the problem lies with UrlFetchApp"Accept": "*/*" to the headers, I found out that the error comes from Cloudflare, along with the message Please enable cookies."User-Agent": "MyBot/1.0" doesn't change anythingI 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:
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.
You need to set the user agent per this format https://discord.com/developers/docs/reference#user-agent
User-Agent: DiscordBot ($url, $versionNumber)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With