So what I'm trying to do is I'm creating some kind of dashboard for my bot and I want to get the current guilds roles. When I try to do that, I get {'message': '401: Unauthorized', 'code': 0}
as response. I tried everything and looked at multiple questions as well as issues on github
json.loads(discord_oauth.discord.get(f"/api/guilds/{server}/roles", headers={"Authorization": "client-secret-here"}).content)
If you ask why I didnt put Bearer
in front of my client secret thats because the library I'm using already puts that in front. So the header will return like this: {"Authorization": "Bearer client-secret-here"
(I tried putting that too but it didn't work either)
I tried doing it with requests.get() too but it didnt work either. I always got {'message': '401: Unauthorized', 'code': 0}
as response. How can I fix this?
(This code doesn't work only when I'm trying to get guild channels and guild roles. It works with guild and user info)
My scopes are: ["guilds", "identify"]
HTTP 401 responses are always authorization errors, telling you that you're either not providing the correct credentials, or your credentials are expired.
Did you get a client token from Discord? If so, are you using the syntax provided by the Discord REST API documentation for bots? Based on what I'm seeing, your line should look something like:
token = 'MTk4NjIyNDgzNDcxOTI1MjQ4.Cl2FMQ.ZnCjm1XVW7vRze4b7Cq4se7kKWs'
headers = {"Authorization": f"Bot {token}"}
result = discord_oauth.discord.get(f"/api/guilds/{server}/roles", headers=headers).content
data = json.loads(result)
If you've followed these directions and you're still getting 401 errors, I would bet that your credentials are invalid, implying the token has been revoked. That would mean you should probably get a new token.