Home > Software design >  How to fix "TypeError: message.member.hasPermission is not a function" in Discord.js?
How to fix "TypeError: message.member.hasPermission is not a function" in Discord.js?

Time:10-31

I was making Permissions Handler and I get the error "TypeError: message.member.hasPermission is not a function". What's my mistake?

        const validPermissions = [
        "CREATE_INSTANT_INVITE",
        "KICK_MEMBERS",
        "BAN_MEMBERS",
        "ADMINISTRATOR",
        "MANAGE_CHANNELS",
        "MANAGE_GUILD",
    ]

    if(command.permissions.length){
        let invalidPerms = []
        for(const perm of command.permissions){
          if(!validPermissions.includes(perm)){
            return console.log(`Invalid Permissions ${perm}`);
          }
          if(!message.member.hasPermission(perm)){
            invalidPerms.push(perm);
          }
        }
        if (invalidPerms.length){
          return message.channel.send(`Missing Permissions: \`${invalidPerms}\``);
        }

CodePudding user response:

message.member.hasPermission() has been removed in djs v13, you need to use message.member.permissions.has() now!

  • Related