title: Discord Add Guild Member 401 Error Despite Apparently Valid Access Token
body: <p>I am new to Discord's API, and I am working a project which needs to be able to add a guild member programmatically.  I've learned how to get an authorization code (with identify and guilds.join scopes), redeem it for an access token, and get a user's ID.  The last step is to use the access code and user ID to add the guild.  This command is detailed here:</p>
  
  <p><a href="https://discordapp.com/developers/docs/resources/guild#add-guild-member" rel="noreferrer">https://discordapp.com/developers/docs/resources/guild#add-guild-member</a></p>
  
  <p>It seems I need to send a PUT request to this URL:</p>
  
  <p><a href="https://discordapp.com/api/guilds/[GuildID]/members/[UserID]" rel="noreferrer">https://discordapp.com/api/guilds/[GuildID]/members/[UserID]</a></p>
  
  <p>But this results in this response:</p>
  
  <blockquote>
    <p>{"code": 0, "message": "401: Unauthorized"}</p>
  </blockquote>
  
  <p>I have tried including the access token in the Authorization header:</p>
  
  <blockquote>
    <p>Authorization: Bearer [Redacted]</p>
  </blockquote>
  
  <p>I've also tried adding a JSON body to the request:</p>
  
  <blockquote>
    <p>{"access_token":"[Redacted]"}</p>
  </blockquote>
  
  <p>Neither has worked.  Unsurprisingly, using both at the same time hasn't worked either.</p>
  
  <p>I wondered if this was a permissions issue, but Discord confirms I have the guilds.join scope.  This is the JSON I receive when exchanging my authorization code for an access token:</p>
  
  <blockquote>
    <p>{"access_token": "[Redacted]", "token_type": "Bearer", "expires_in": 604800, "refresh_token": "[Redacted]", "scope": "identify guilds.join"}</p>
  </blockquote>
  
  <p>The identify scope works since I am able to retrieve the user and its ID.  But guilds.join doesn't seem to work.</p>
  
  <p>I have included some test code below.  I have marked "Option 1" and "Option 2" lines to signify that I wouldn't typically do both of these access code methods in the same request.  But as I mentioned earlier, I did try both, and I still got a 401 error.</p>
  
  <pre><code>using (WebClient client = new WebClient())
  {
      client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
      client.Headers.Add(HttpRequestHeader.Authorization, "Bearer [Redacted]");//Option 1
      string output = client.UploadString
      (
          "https://discordapp.com/api/guilds/[GuildID]/members/[UserID]",
          WebRequestMethods.Http.Put,
          "{\"access_token\":\"[Redacted]\"}"//Option 2
      );
  }
  </code></pre>
  
  <p>Because I'd like to understand the intracacies of how this works, I'd prefer to know how to do this with ordinary Web requests (such as HttpWebRequest and WebClient, as opposed to using some OAuth library).</p>