Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

375
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda