const response = await fetch(`https://discordapp.com/api/oauth2/token`, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: JSON.stringify({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
redirect_uri: redirectURL,
grant_type: 'authorization_code',
code: code,
}),
});
When I run the above code, it returns with { error: 'invalid_grant' }
and I do not know why. Are there any fixes to this? Thank you.
I fixed it, all I had to do was to use querystring
instead of JSON.