Fetching avatar and name from Discord ID

How can i get a discord avatar and a discord name just from their discord id, is there a way to fetch that? Or some url form where i need to put in the id for it to give me an avatar.
15 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Flox
FloxOP2mo ago
Node version: v22.12.0 [email protected]
d.js docs
d.js docs2mo ago
:method: UserManager#fetch() [email protected] Obtains a user from Discord, or the user cache if it's already available.
Mark
Mark2mo ago
Fetch the user, it will have basic information available even if they don't share a server with the client
Flox
FloxOP2mo ago
I still cant get it to work even tho i used the docs...
Amgelo
Amgelo2mo ago
show your code
Flox
FloxOP2mo ago
for (const vouch of vouches) {
const discordUserId = vouch.vouched_by_id;
if (discordUserId) {
try {
const discordUser = await discordClient.users.fetch(discordUserId);
vouch.vouched_by_name = discordUser.username;
vouch.vouched_by_avatar = `https://cdn.discordapp.com/avatars/${discordUser.id}/${discordUser.avatar}.png`;
for (const vouch of vouches) {
const discordUserId = vouch.vouched_by_id;
if (discordUserId) {
try {
const discordUser = await discordClient.users.fetch(discordUserId);
vouch.vouched_by_name = discordUser.username;
vouch.vouched_by_avatar = `https://cdn.discordapp.com/avatars/${discordUser.id}/${discordUser.avatar}.png`;
Flox
FloxOP2mo ago
No description
Flox
FloxOP2mo ago
There you go.
Amgelo
Amgelo2mo ago
you aren't supossed to make the url manually, just use the avatarURL method
d.js docs
d.js docs2mo ago
:method: User#avatarURL() [email protected] A link to the user's avatar.
Flox
FloxOP2mo ago
Can you send an example of how i should do it in my code? It would be super helpfull.
Amgelo
Amgelo2mo ago
const url = discordUser.avatarURL()
Flox
FloxOP2mo ago
alright thanks boss
d.js docs
d.js docs2mo ago
Explaining <Class> and Class#method notation: learn more

Did you find this page helpful?