Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda