Reputation: 55
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?
Upvotes: 2
Views: 14039
Reputation: 618
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.
Upvotes: 4
Reputation: 903
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()
Upvotes: 2