Bharat
Bharat

Reputation: 153

Discord API 401: Unauthorized error

I'm trying to get audit logs from my server using discord API. I'm sending my authorization token in headers but it's still returning error 401.

My code:

headers = {
    'authorization': AUTH_TOKEN        
}

params = {
    'limit':'50',
    'user_id': USER_ID,
    'action_type': '40',
    'authorization': AUTH_TOKEN
}

r = requests.get(f'https://discordapp.com/api/v6/guilds/{SERVER_ID}/audit-logs', params=params)

Output:

{"code": 0, "message": "401: Unauthorized"}

I tried sending user-agent and stuff like that in headers but it doesn't seem to work.

Upvotes: 8

Views: 45282

Answers (1)

Cherona
Cherona

Reputation: 814

If you're using a bot, you must prefix your Authorization header token with 'Bot'

i.e.

headers = {
    'authorization' : 'Bot asdhgaisudg7asd',
}

See https://github.com/discord/discord-api-docs/issues/602

Upvotes: 17

Related Questions