Discord Add Guild Member 401 Error Despite Apparently Valid Access Token

点点圈 提交于 2019-11-29 11:37:45

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.

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