最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

api - Javascript Discord get profile picture - Stack Overflow

programmeradmin4浏览0评论

I am doing a website where you enter the user ID to get the discord pfp. The problem is i can't find any url or api with the user image. I am not trying to do a bot but a website. Can someone help me?

I am doing a website where you enter the user ID to get the discord pfp. The problem is i can't find any url or api with the user image. I am not trying to do a bot but a website. Can someone help me?

Share Improve this question asked Jul 14, 2021 at 13:33 SkullySkully 551 gold badge1 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

The Discord API documentation allows apps with the appropriate permissions to query user information (Get User API) which returns a User object containing an avatar field. The avatar field is a hash that can be used with the User Avatar CDN endpoint to retrieve the user's avatar.

It's worth noting that none of this can be done with Javascript in your website due to the Same Origin Policy which prevents client-side Javascript from making web requests to origins other than the one your website is loaded from. CORS could allow this, but it would be on Discord to allow your site to make requests.

Instead you would make some request to your site's backend and have it make the requests to Discord's APIs. You could keep using Javascript for this, via Node.js, but you also build your backend in just about any other language you like.

The 'displayAvatarURL()' method returns the url of the avatar of the user.

Use it like this:

let avatarUrl = user.displayAvatarURL()

More information about it: discord.js - displayAvatarURL()

发布评论

评论列表(0)

  1. 暂无评论