Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

412
Views
TypeError: Cannot read properties of undefined (reading 'roles')

So im making a command to kick people(ofcourse) and theres a part where i wanna let people know if they dont have permision or the bot dosent have permision to kick the specified person, but then i came across this error whenever I tried to run the code

const mentionedRank = mentionedMember.roles.highest.position; ^ TypeError: Cannot read properties of undefined (reading 'roles')

My whole code for that command is:

    if (isCommand === 'kick') {
        const mentionedMember = message.mentions.members.first();
        const mentionedRank = mentionedMember.roles.highest.position;
        const memberRank = message.member.roles.highest.position;
        const botRank = message.guild.me.roles.highest.position;
        var embed = new Discord.MessageEmbed()

        let reason = args.slice(1).join(' ')
        if(!reason) {
             reason = 'no defined reason'
        }

        if(!message.member.permissions.has('KICK_MEMBERS'))
            embed = embed
            .setDescription('You do not have the permission to kick a user!')
            .setColor("BLUE")
            message.reply({embeds: [embed]})
        if(!message.guild.me.permissions.has('KICK_MEMBERS'))
            embed = embed
            .setDescription('I do not have the permission to kick a user')
            .setColor("BLUE")
            message.reply({embeds: [embed]})
        if(memberRank <= mentionedRank){
            embed = embed
            .setDescription('You cannot kick that user as they have a equal/higher rank as you')
            .setColor("BLUE")
            message.reply({embeds: [embed]})
        }
        if(botRank <= mentionedRank){
            embed = embed
            .setDescription('I cannot kick that user as they have a equal/higher rank than me')
            .setColor("BLUE")
            message.reply({embeds: [embed]})
        }
        
        if(!args[0]){
            embed = embed
            .setDescription('Please specify the user that you want to kick!')
            .setColor("BLUE")
            message.reply({embeds: [embed]})
        }
        if(member){
        member.kick();
        let guildname = client.guilds.fetch()
        embed = embed
        .setTitle(`${mentionedMember} kicked!`)
        .setDescription(`${mentionedMember} was kicked from the server for ${reason}.`)
        .setColor("BLUE")
        message.reply({embeds: [embed]})
    } else{
        embed = embed
        .setDescription(`"${args[0]}" was not found`)
        .setColor("BLUE")
        message.reply({embeds: [embed]})
    }
}          
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!