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.
CodePudding user response:
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")
}
}
}
CodePudding user response:
This should work:
if (user.permission.has("KICK_MEMBERS"){
// put code here
} else {
return;
}