Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

377
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda