Discord API 401:未经授权的错误 [英] Discord API 401: Unauthorized error

查看:72
本文介绍了Discord API 401:未经授权的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Discord API 从我的服务器获取审核日志.我在标头中发送我的授权令牌,但它仍然返回错误 401.

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.

我的代码:

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)

输出:

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

我尝试在标题中发送用户代理和类似内容,但似乎不起作用.

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

推荐答案

如果您使用机器人,则必须在 Authorization 标头标记前加上Bot"

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

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

参见 https://github.com/discord/discord-api-文档/问题/602

这篇关于Discord API 401:未经授权的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆