[英]Why avatar url from oldMember and newMember are the same in a guildMemberUpdate? (Discord.js)
I'm trying to send a message in a channel when someone changes profile picture, but it's not working because always url from oldUser and newUser are the same (twice are the new avatar url), I do something similar for nickname changes and it actually is working well..当有人更改个人资料图片时,我正在尝试在频道中发送消息,但它不起作用,因为 oldUser 和 newUser 的 url 总是相同(两次是新头像 url),我对昵称更改做了类似的事情,实际上运作良好..
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);
}
});
log after change profile picture, oldMember and newMember avatar url are the same (twice are the new avatar url):更改头像后登录,oldMember和newMember头像url是一样的(两个是新头像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.我认为这是一个已知问题,它的工作原理是这样的,因为如果用户信息发生更改,Discord 会同时发送
PRESENCE_UPDATE
和GUILD_MEMBER_UPDATE
。
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.首先,在
PRESENCE_UPDATE
discord.js 确定更改并将其应用于缓存,在GUILD_MEMBER_UPDATE
上,基础用户已经从PRESENCE_UPDATE
更改,因此旧用户不能与旧成员一起发出。 So, every time a user is updated, GUILD_MEMBER_UPDATE
will not hold the "old" data, just the updated version.因此,每次更新用户时,
GUILD_MEMBER_UPDATE
不会保存“旧”数据,而只会保存更新后的版本。 That's the reason oldMember.user.displayAvatarURL()
is the same as newMember.user.displayAvatarURL()
.这就是
oldMember.user.displayAvatarURL()
与newMember.user.displayAvatarURL()
相同的原因。
I know it probably wasn't the answer you were expecting.我知道这可能不是您期望的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.