Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord Oauth2 Join Guild

const guildMembersResponse = fetch(`http://discordapp.com/api/guilds/440494010595803136/members/278628366213709824`,
            {
              method: 'PUT',
              headers: {
                Authorization: `Bearer TOKEN`,
              },
            });
            setTimeout(() => {
                console.log(guildMembersResponse)
            }, 500);

I want to join a user to my Discord server with his userid and his token in nodejs, but if I request the Dicord api I get an error:

Promise {
 Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: 
  null },
  [Symbol(Response internals)]:
  { url:
  'https://discordapp.com/api/guilds/440494010595803136/members/278628366213709824',
   status: 401,
   statusText: 'UNAUTHORIZED',
   headers: [Headers] } } }

I am using the node-fetch library!

like image 838
G33RY Avatar asked Oct 17 '22 08:10

G33RY


1 Answers

I just had to replace the "ContentType" to "Content-Type" in the headers!

headers: {
  "Authorization": "Bot [botToken]",
  "Content-Type": "application/json",
}
like image 64
G33RY Avatar answered Nov 15 '22 06:11

G33RY