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

131
Views
Role add discord.js
require('discord-inline-reply');
const { MessageEmbed } = require("discord.js");
const { ownerID } = require("../../owner.json")
const db = require('quick.db')
module.exports = {
  config: {
      name: "roleadd",
          description: "Add a role to a member",
              usage: "m/roleadd <member mention/id> <role mention/role id>",
                  aliases: ['role add', 'radd', 'role']
                    },
                      run: async (client, message, args) => {

    let rMember = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
    if(!rMember) return message.channel.send("Please provide a user to add a role too.")
    let role = message.guild.roles.cache.find(r => r.name == args[1]) || message.guild.roles.cache.find(r => r.id == args[1]) || message.mentions.roles.first()
    if(!role) return message.channel.send("Please provide a role to add to said user.") 


    if(rMember.roles.cache.has(role.id)) {
      return message.channel.send(`${rMember.displayName}, already has the role!`)
    } else {
      await rMember.roles.add(role.id).catch(e => console.log(e.message))
      message.channel.send(`${rMember.displayName} has been added to **${role.name}**`)
    }
  },
  };

The bot just gives role even if the user has a role lower than the user. I want to add a role position checking. Can anybody help?

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

0

To get member highest role you should use GuildMemberRoleManager.highest, and use Role.rawPosition to get its position in list!

So what you need is:

if (rMember.roles.highest.rawPosition < role.rawPosition) return;
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!