Discord Add Guild Member 401 Error Despite Apparently Valid Access Token

I am answering my own question as I may have figured this out. It works when I execute the below:

using (WebClient client = new WebClient())
{
    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
    client.Headers.Add(HttpRequestHeader.Authorization, "Bot [Redacted]");
    string output = client.UploadString
    (
        "https://discordapp.com/api/guilds/[GuildID]/members/[UserID]",
        WebRequestMethods.Http.Put,
        "{\"access_token\":\"[Redacted]\"}"
    );
}

Notice that I changed from a content type of "application/x-www-form-urlencoded" to "application/json." I changed from using an Authorization header of "Bearer" to "Bot," and I am using my bot's token. I am using the same access token as before. I plan to accept this answer if no better solutions come in.


Comments

  1. Colton

    • 2016/3/29

    I changed from using an Authorization header of "Bearer" to "Bot," and I am using my bot's token. I am using the same access token as before 

  2. Griffin

    • 2020/5/15

    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.

  3. Devin

    • 2020/7/5

    I am certain that my access token is valid and the request should be too. I have a bot with bot guilds.join scope which is from an 

  4. Maurice

    • 2015/6/28

    6 Discord Add Guild Member 401 Error Despite Apparently Valid Access Token 6 Apparently Random Error: "Antiforgery token validation failed. The antiforgery cookie token and request token do not match."

  5. Tripp

    • 2019/7/18

    I am getting a 401 unauthorized when i use GET on /guilds/{guild.id}/channels, Does this have something to do with the gateway?

  6. Demetrius

    • 2019/11/26

    Use Case: DiscordServers.com uses the Add Guild Member endpoint to add users to the server they want to join. Server owners would really appreciate the ability to specify what channel people see when they join the server, without updating the order of channels.

  7. Reign

    • 2017/3/17

    Abstract. My dissertation links two popular revolts in Seville, in 1520-1 and 1652, both of which had as their focus the artisan parish of Omnium Sanctorum, 

  8. Lennon

    • 2018/10/8

    in my project i use laravel with ouath from socialite discord composer package, by default socialite only use identity and email, and you must add guild.joins scope manually, you can add guild.joins in vendor->scocialiteproviders->discord->provider.php.

  9. Porter

    • 2016/5/18

    approximate_member_count? integer, approximate number of members in this guild, returned from the GET /guilds/<id> endpoint when with_counts is true.

  10. Augustine

    • 2020/9/5

    Because Add Guild Member itself has an entirely different use case. It allows you to very finely control who you let into a Discord server and when, because with the added OAuth2 step involved you can inspect the discord users account before adding them, possibly cross-referencing them with a 3rd party site (i.e. forum membership or subscriptions)

  11. Marvin

    • 2019/9/18

    Although CPB does not produce or distribute programming, we welcome all comments access to freely available TV content – over-the-air on local member 

  12. Cruz

    • 2017/9/26

    Please describe the problem you are having in as much detail as possible: Guild.addMember despite being called with a valid user ID, auth token and invoked from a bot where said user authenticated himself with the guilds.join scope, retu

  13. Kayson

    • 2017/2/15

    I would add one principal comment on the results of the Commit- The members of this Committee have served with utmost diligence and dedication.

  14. Antonio

    • 2017/8/1

    I am trying to add a user when authenticated via Discords Oauth2. Techstack: Node.js, Javascript with Vue.js, Axios The scopes are "identify email guilds.join" My first two API calls work fine, giving me the bearer token, then the user w

  15. Omari

    • 2019/9/21

    Nearly every area of the law has undergone change and develop ment since publication of the Fifth· Edition in 1979. This period has.

  16. Ahmad

    • 2021/5/17

    ries hearing cases in which either a member of the black community Although most northern blacks gained access to the regular.

Comments are closed.

Recent Posts