Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SOLVED: DISCORD.JS V13 TypeError: Cannot read property 'has' of undefined

PROBLEM SOLVED

I’m doing a bot discord, I was trying to check if member mentioned has permissions
but I have this problem:

if(member.permissions.has("ADMINISTRATOR")) return message.reply({content: ["no"]})
                      ^

TypeError: Cannot read property 'has' of undefined

this is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const { Client, Message } = require("discord.js");

module.exports = {
    name: "user",
    description: "comando a risposta",
    aliases: ["boop", "test"],
    /** 
     * @param {Client} client 
     * @param {Message} message 
     * @param {String[]} args 
     */
    run: async (client, message, args) => {
        const member = message.mentions.users.first();
        if(member.permissions.has("ADMINISTRATOR")) return message.reply({content: ["he has the admin"]})
        message.reply(`${member.tag}`)
    }
}

now it solved with:

        const member = message.mentions.members.first()
        if(member.permissions.has("ADMINISTRATOR")) {
            message.reply(`${member.tag} ha l'admin`)
        }
        if(!member.permissions.has("ADMINISTRATOR")) {
            message.reply(`${member.tag} non ha l'admin`)

thanks everyone

>Solution :

You are getting a User object which doesn’t have .permissions. Get the GuildMember object instead with message.mentions.members.first()

const member = message.mentions.members.first()

Users are not the same as GuildMembers: See What is the difference between a User and a GuildMember in discord.js?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading