• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

132
Views
How to solve if roles changed bot shows nickname updated
  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.

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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)
almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error