Pooyan
Pooyan

Reputation: 490

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

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

Upvotes: 0

Views: 2552

Answers (1)

CherryDT
CherryDT

Reputation: 29012

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();
//                              ^^^^^^^

Upvotes: 1

Related Questions