I'm trying to send a message in a channel when someone changes profile picture, but it's not working because url from oldUser and newUser are always the same (both are the new avatar url), I did something similar for nickname changes and it actually is working well..
bot.on("guildMemberUpdate", (oldMember, newMember) => {
//checks if the change is the nickname
if (oldMember.displayName != newMember.displayName) {
console.log(`(NEW ACTIVITY): @${oldMember.user.username} changed username. @${oldMember.displayName} was the username before update, @${newMember.displayName} is the username after update`);
//build embed
messages.usernameUpdate(bot, oldMember, newMember);
}
console.log(oldMember.user.displayAvatarURL());
console.log(newMember.user.displayAvatarURL());
//checks if the change is the profile picture
if (oldMember.user.displayAvatarURL() != newMember.user.displayAvatarURL()) {
console.log(`(NEW ACTIVITY): @${newMember.user.username} updated profile picture`);
//build embed
messages.photoUpdate(bot, oldMember, newMember);
}
});
logs after change profile picture, oldMember and newMember avatar url are the same (new avatar url):
https://cdn.discordapp.com/avatars/826073829302206525/4eab82e784ca3caa8ed1ba18631541b2.webp
https://cdn.discordapp.com/avatars/826073829302206525/4eab82e784ca3caa8ed1ba18631541b2.webp
I think it's a known issue and it works like this because Discord sends both PRESENCE_UPDATE
and GUILD_MEMBER_UPDATE
if the user information is changed.
First, on the PRESENCE_UPDATE
discord.js determines the change and apply it to the cache and on the GUILD_MEMBER_UPDATE
the underlying user is already changed from the PRESENCE_UPDATE
so the old user cannot be emitted with the old member. So, every time a user is updated, GUILD_MEMBER_UPDATE
will not hold the "old" data, just the updated version. That's the reason oldMember.user.displayAvatarURL()
is the same as newMember.user.displayAvatarURL()
.
I know it probably wasn't the answer you were expecting.