Arcitezz
Arcitezz

Reputation: 33

Joined member avatar displayed in thumbnail of embed - Discord.js

So I've created a message embed that get's sent to a channel whenever a member joins the server. I used the following code for this.

client.on('guildMemberAdd', guildMember => {

let welcomeRole = guildMember.guild.roles.cache.find(role => role.name === 'ROLE');

guildMember.roles.add(welcomeRole);

let welcomeEmbed = new Discord.MessageEmbed()

    .setColor('#202225')
    .setTitle('New member spotted!')
    .setDescription(`Welcome ${guildMember}!`)
    .setThumbnail(guildMember.displayAvatarURL())


guildMember.guild.channels.cache.get('CHANNEL_ID').send(welcomeEmbed);

So the user's avatar doesn't show, although a normal image does of course. I'm suspecting it's because I'm not using the user class, could be something else, I have no idea.

My question is then, how can I display the joined user's avatar in the embed's thumbnail?

Upvotes: 1

Views: 3121

Answers (2)

Jannik Schmidtke
Jannik Schmidtke

Reputation: 1247

I would recommend doing:

.setThumbnail(guildMember.user.displayAvatarURL({ dynamic: true }))

This will show the users avatar and if it's animated, it will be displayed animated.

Upvotes: 2

Itamar S
Itamar S

Reputation: 1565

You cannot get the avatar of a GuildMember object, but would first have to convert it into a User object.

This can be simply done using:

.setThumbnail(guildMember.user.displayAvatarURL())

Upvotes: 1

Related Questions