Skip to content

User avatar fetch v13 #8577

Closed Answered by kyranet
kardespro asked this question in Q&A
Aug 31, 2022 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

Superseding @xrenata's answer as it's incorrect:

const user = await client.users.fetch('id');
const avatar = user.displayAvatarURL();
// Use `avatar` here

The issue with the previous "correct" answer is that users.fetch returns a Promise<User>, and the Promise object does not have a property (nor a method) with the name of displayAvatarURL, so it becomes undefined and eventually throws, this makes the code invalid.

However, the User class has both avatarURL() (returns null when the user uses their default avatar) and displayAvatarURL() (returns default avatar if none is set).

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@kardespro
Comment options

@manuelvleeuwen
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by kyranet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants