Cannot read properties of undefined (reading 'comparePositionTo'

Viewed 24

I'm making a kick slashCommand in discord.js v13 and i was trying to compared the user roles and the target role but it doesn't work, I don't know why is that

here's my code:

If(interaction.member.highest.comparePositionTo(target.roles.highest.position > 0)) {
      const kickErr = new MessageEmbed()
        .setDescription(`You cannt kick this member because their role is higher/equal to yours.`)
        .setColor(ee.color)
      return interaction.reply({ embeds: [kickErr] })
    } else if (interaction.guild.me.roles.highest.comparePositionTo(target.roles.highest.position > 0)) {
      const kickErr2 = new MessageEmbed()
        .setDescription(`I cannot kick this member because their role is higher/equal to mine.`)
        .setColor(ee.color)
      return interaction.reply({ embeds: [kickErr2] })
    }
1 Answers

It looks like you have this error because on the first line of your code you used

if(interaction.member.highest.comparePositionTo(targ...

Instead of

if(interaction.member.roles.highest.comparePositionTo(targ...

Also, next time you post a question on stackoverflow, make sure to add the full error stack in your post to make it easier to understand

Related