I have asked a question somewhat related to this already, but the answer I got was slightly flawed, and I didn't notice until now. I want the add role command to work only when the message.author's highest role is above the mentioned user's highest role. This was the answer I got from the last time I asked a query:
const highest = member.roles.highest; // this is the members highest role
// if role is higher or equal to highest role
if(highest.comparePositionTo(role) <= 0)
return message.channel.send('You cannot add roles equal/higher to that member\'s highest role')
although it worked, it was not what I was looking for, this command will only work when the role message.author mentioned is below the mentioned user's highest role. So I modified it to this:
const { MessageEmbed } = require("discord.js");
module.exports = {
name: "addrole",
description: "adds a role to a member",
execute: async (message , args) => {
if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send("Invalid Permissions")
let member = message.mentions.members.first();
let role = message.mentions.roles.first();
if (!member)
return message.reply("Please mention a valid member of this server");
if (!role) return message.reply("please mention a valid role of this server");
const highest = message.author.roles.highest;
if(highest.comparePositionTo(role) <= 0)
return message.channel.send(`You cannot add roles equal/higher to that member's highest role`)
let addroleembed = new MessageEmbed()
.setTitle(`:white_check_mark: ${role.name} has been added to ${member.user}`)
.addField(`hippity hoppity this role is now ${member.user}'s property`)
.setFooter(`Action performed by ${message.author.tag}`)
.setColor('77B255')
addroleembed.setTimestamp();
member.roles.add(role);
message.channel.send(addroleembed)
}}
but this does not seem to work. I get the error "TypeError: cannot read propert 'highest' of undefined. I would appreciate it if someone could help me out here
message.author
returns a User andmessage.member
is a GuildMember. It's the same issue. – Lioness100