add role

hi so ive been trying a lot to make this work but it just wont

if (command === "addrole") {
    if (!message.member.permissions.has(PermissionsBitField.Flags.ManageRoles)) {
      return message.channel.send('no perms')
    }
if (!message.guild.members.me.permissionsIn(message.channel).has(PermissionsBitField.Flags.ManageRoles)) {
      return message.channel.send('no perms')
    }
    if (!args[0]) return message.channel.send("error reply")
    let nombrea = args[0]
    let user = message.mentions.users.first() || client.users.cache.get(args[0]) || client.users.cache.find(user => user.username === nombrea)
    let role = message.mentions.roles.first() || message.guild.roles.cache.find(r => r.id == args[1])
    if (!user) return message.channel.send("errpr reply")
    if (!args[1]) return message.channel.send("error reply")
    if (!role) return message.channel.send("error reply") 
    if (!role.editable) return message.channel.send("error reply")
  // if (user.roles.cache.has(role.id)) return message.channel.send("reply")

    if (role.comparePositionTo(message.member.roles.highest) >= 0) return message.channel.send("No puedes añadir un rol igual o superior al tuyo!")
  //  if (message.member.roles.highest.comparePositionTo(user.roles.highest) <= 0) return message.channel.send("reply")
    try {
    user.roles.add(role)
    } catch (error){
      console.log(error)
      console.log(user)
      console.log(role)
      return message.channel.send('error reply')
      }
    return message.channel.send(`reply`)
  }


im updating my code from v12.3.1 to 14.13.0 and im trying to update this code but there are 3 errors

first one, on the first // there is an error with the 'has'
second one, on the second //there is an error with 'highest'
and finally, on user.roles.add(role) there is always the error 'cannot read properties of undefined reading 'add''

and all of the console.log give me a real role and a real member, also im testing on a test server so i have perms, the bot has perms, the user is below the bot, the role is below the bot role

idk what to do
Was this page helpful?