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

379
Views
TypeError: role.setPermissions is not a function even though TypeScript says it is

I was creating a command that loops through all roles in a server, and removes/adds a selected permission (if it can). Hovering over it shows the description of the function.

async execute(client, msg, args, cooldowns, guildForPre, prefix) {
    if(msg.member.permissions.has("MANAGE_ROLES")) {
        let roles = (await msg.guild.roles.fetch()).cache;
        let highPos = getRoleByMention(args[1], msg.guild)?.position || msg.guild.roles.highest.position
        let lowPos = getRoleByMention(args[2], msg.guild)?.position || msg.guild.roles.everyone.position
        roles = roles.filter(r => r.permissions.has(args[0]))
        roles = roles.filter(r => r.position <= highPos && r.position >= lowPos)
        let replaced = ''
        for await (const [, role] of roles) {
            if(role.position >= msg.guild.me.roles.highest.position || role.position >= msg.member.roles.highest.position) continue;
            await role.setPermissions(role.permissions.remove(args[0]))
            (replaced.length) ? replaced += `, ${role.name}` : replaced += `${role.name}`
        }
        msg.channel.send("Replaced roles: " + replaced)
    }
}

getRoleByMention function:

function getRoleByMention(mention, guild) {
    const id = mention.slice(3, mention.length-1)
    return guild.roles.cache.get(id)
}

My command handler arguments are put in correctly, and the command entered is the following:

m.removeRolePerm MANAGE_MESSAGES @Dyno @Dyno

Is it because they are the same role? The docs say it's a valid function. I am using v12.

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

0

The problem is actually the statement after. This is because of the lack of semi-colons. Adding a semi-colon should make it work. Changing it to this will remove the error and will make it work too

await role.setPermissions(role.permissions.remove(args[0]))
           if (replaced.length) replaced += `, ${role.name}`
           else replaced += `${role.name}`
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!