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 badges2 Answers
Reset to default 4The 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()