简体   繁体   English

有没有办法使用 discord API 中的机器人令牌获取机器人数据?

[英]Is there a way to get bot data using the bot token in discord API?

I'm trying to get information about a bot using the bot token, like the way to get user, passing on the header Authorization: Bearer ${userToken}.我正在尝试使用机器人令牌获取有关机器人的信息,例如获取用户的方式,传递 header 授权:Bearer ${userToken}。 I'm sending a request to the route GET https://discord.com/api/oauth2/applications/@me passing on the header Authorization: Bearer ${botToken}, and the response is 401. But if I send a request to the route GET https://discord.com/api/oauth2/users/@me with my token in the header, I got my data.我正在向路由 GET https://discord.com/api/oauth2/applications/@me发送请求,传递 header 授权:Bearer ${botToken},响应为 401。但如果我发送请求使用我在 header 中的令牌到路线 GET https://discord.com/api/oauth2/users/@me ,我得到了我的数据。 I don't have sure if the bot token can be used for this, I check on the docs, and I found this https://discord.com/developers/docs/topics/oauth2#get-current-application-information , but I don't understand what I need to pass in the header to get the data.我不确定机器人令牌是否可以用于此,我查看了文档,发现了这个https://discord.com/developers/docs/topics/oauth2#get-current-application-information ,但我不明白我需要在 header 中传递什么来获取数据。

Yes, and you're very close to the correct solution.是的,您非常接近正确的解决方案。

The issue is with the "Authorization" header, instead of "Bearer" you should use "Bot" when using a token for a bot user.问题在于“授权”header,而不是“Bearer”,在为机器人用户使用令牌时应该使用“Bot”。

In your case the header should be:在您的情况下, header 应该是:

Authorization: Bot ${botToken}

CURL example: CURL 示例:

curl --location --request GET 'https://discord.com/api/oauth2/applications/@me' \
--header 'Authorization: Bot <BOT TOKEN HERE>'

Regarding the question about "https://discord.com/api/oauth2/users/@me", try using "https://discord.com/api/users/@me" instead.关于“https://discord.com/api/oauth2/users/@me”的问题,请尝试使用“https://discord.com/api/users/@me”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM