Home > database >  TypeError: Cannot read properties of undefined (reading 'has')
TypeError: Cannot read properties of undefined (reading 'has')

Time:04-10

I want to check if the member is the owner of the server, but I am getting an error. My code:

const member = message.mentions.users.first();
        const reason = args.slice(1).join(' ') || 'No reason specified.'

        
        if (member.permissions.has('MANAGE_GUILD')) return message.reply( 'I cannot moderate the owner of the server.')

Error:

TypeError: Cannot read properties of undefined (reading 'has')

I am using discord.js v13 and Node.js 16

CodePudding user response:

A User doesn't have a permissions property.

However, a GuildMember has.

The solution is therefore not to access the first User in the mentions as you do now (into a variable confusingly called member) but the first GuildMember, using the members property of the MessageMentions:

const member = message.mentions.members.first();
//                              ^^^^^^^
  • Related