Discord Oauth2 Join Guild

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 02:42:25

问题


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!


回答1:


I just had to replace the ContentType to "Content-Type"

headers: {
  "Authorization": "Bot [botToken]",
  "Content-Type": "application/json",

},




回答2:


A 401 error would mean that you haven't provided the correct scope for the oauth link. Read more about Discord's OAuth scopes over at https://discordapp.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes. Quoting the docs, you would need the guilds.join scope.

Moreover, the docs quote:

guilds.join and bot require you to have a bot account linked to your application. Also, in order to add a user to a guild, your bot has to already belong to that guild.

So make sure your app fulfills the above requirement.

If you have made sure that you have followed the above steps, and you still cannot get it working, you would have to share the OAuth link with us to help you investigate further



来源:https://stackoverflow.com/questions/53962204/discord-oauth2-join-guild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!