当有人更改头像时,我尝试在通道中发送消息,但它不起作用,因为总是来自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);
}
});更改个人资料图片后的日志,oldMember和newMember头像url相同(两次是新头像url):
https://cdn.discordapp.com/avatars/826073829302206525/4eab82e784ca3caa8ed1ba18631541b2.webp
https://cdn.discordapp.com/avatars/826073829302206525/4eab82e784ca3caa8ed1ba18631541b2.webp发布于 2021-04-04 04:42:40
我认为它是一个known issue,它的工作方式是这样的,因为如果用户信息发生变化,Discord会同时发送PRESENCE_UPDATE和GUILD_MEMBER_UPDATE。
首先,在PRESENCE_UPDATE上,discord.js确定更改并将其应用于缓存,并且在GUILD_MEMBER_UPDATE上,底层用户已经从PRESENCE_UPDATE更改,因此不能使用旧成员发送旧用户。因此,每次用户更新时,GUILD_MEMBER_UPDATE将不会保存“旧”数据,而只保存更新后的版本。这就是oldMember.user.displayAvatarURL()与newMember.user.displayAvatarURL()相同的原因。
我知道这可能不是你想要的答案。
https://stackoverflow.com/questions/66935373
复制相似问题