簡體   English   中英

有沒有辦法使用 discord API 中的機器人令牌獲取機器人數據?

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

我正在嘗試使用機器人令牌獲取有關機器人的信息,例如獲取用戶的方式,傳遞 header 授權:Bearer ${userToken}。 我正在向路由 GET https://discord.com/api/oauth2/applications/@me發送請求,傳遞 header 授權:Bearer ${botToken},響應為 401。但如果我發送請求使用我在 header 中的令牌到路線 GET https://discord.com/api/oauth2/users/@me ,我得到了我的數據。 我不確定機器人令牌是否可以用於此,我查看了文檔,發現了這個https://discord.com/developers/docs/topics/oauth2#get-current-application-information ,但我不明白我需要在 header 中傳遞什么來獲取數據。

是的,您非常接近正確的解決方案。

問題在於“授權”header,而不是“Bearer”,在為機器人用戶使用令牌時應該使用“Bot”。

在您的情況下, header 應該是:

Authorization: Bot ${botToken}

CURL 示例:

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

關於“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