if (!((String(oldMember.nickame)) == (String(newMember.nickname)))) {
gwebhook.send({
embeds: [new Discord.MessageEmbed()
.setAuthor(newMember.guild.name, newMember.guild.iconURL({dynamic: true}))
.setTitle('Member Nickname Update')
.setColor("YELLOW")
.addField('Before', String(oldMember.nickname), true)
.addField('After', String(newMember.nickname), true)]
});
}
It gives logs even when role changed.
The issue here is a simple typo. First, let's simplify your code removing all of those redundant and not-so-pretty String()
casts:
if (!(oldMember.nickame == newMember.nickname)) {
gwebhook.send({
embeds: [new Discord.MessageEmbed()
.setAuthor(newMember.guild.name, newMember.guild.iconURL({dynamic: true}))
.setTitle('Member Nickname Update')
.setColor("YELLOW")
.addField('Before', oldMember.nickname, true)
.addField('After', newMember.nickname, true)]
});
}
That makes the code a lot easier to look at. And now the issue is obvious. You did oldMember.nickame
instead of oldMember.nickname
in your if
statement. Since oldMember.nickame
is undefined
(as it is not an existent property of guild members due to the typo), it will always not be equal to newMember.nickname
. Therefore, whenever a member is updated in any way (whether nickname change, role change, or any other member change), the code inside this if
statement will always be executed. Just fix the typo and the code should work as expected:
if (oldMember.nickname != newMember.nickname)