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

184
Views
How to find th author of a message in discord, and how to use that to figure out if it has the right permissions for a command

I'm trying to figure out if the author a command, has the right permissions to carry out the command. But the console keeps saying TypeError: Cannot read property 'permission' of undefined. Heres my code.

  name: 'mute',
  description: 'mutes someone',
  execute(message,args) { 
    const target = message.mentions.members.first();
    const muteRole = message.guild.roles.cache.find(role => role.name === 'MUTED')
    let sender = message.author
    let role = message.member.roles

   if(!target || !message.user.permission.has('MANAGE_ROLES') ) {
    message.channel.send("You cant mute that member.")
   } else if(message.sender.permission.has('MANAGE_ROLES')) {  
    target.roles.set([muteRole])    
    //target.roles.add(muteRole)
    message.channel.send("User has been muted")
  }
  }
}

I know that it can't find the author, but I don't know how to fix that. Also I think the message.user.permission.has('MANAGE_ROLES') is also wrong, but again I don't know how to fix it. Online it has conflicting information.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ok so I found the answer

const { Permissions } = require('discord.js');

module.exports = {
  name: 'mute',
  description: 'mutes someone',
  execute(message,args) { 
    const target = message.mentions.members.first();
    const muteRole = message.guild.roles.cache.find(role => role.name === 'MUTED')
    let user = message.author;

   if(!target || !message.member.permissions.has('MANAGE_ROLES')) {
    message.channel.send("You cant mute that member.")
   } else if(message.member.permissions.has('MANAGE_ROLES')) {  
    target.roles.set([muteRole])    
    //target.roles.add(muteRole)
    message.channel.send("User has been muted")
  }
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

Replace the message.user.permissions.has('MANAGE_ROLES') with:

message.member.permission.has('MANAGE_ROLES')

This uses the GuildMember object instead of the User object because you can’t fetch roles from a User object.

about 4 years ago · Juan Pablo Isaza Report
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!