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

267
Visualizações
how to handle a DiscordAPIError: Missing Permissions in discord.js when removing roles

I have a bot that removes all roles from a user, however, when the bots role is below the role it is trying to remove. It obviously doesn't have permissions so it throws the error DiscordAPIError: Missing Permissions, crashing my bot. How can i handle this to message.reply(member + 'roles are too high for me to remove') When this happens as i cant think of a way to code this in. Heres the function that removes the roles at the moment:

if (message.member.permissions.has('ADMINISTRATOR')) {
            if (!args[0]) {message.reply('you need to ping someone to smac after =smacmedown')
            } else {
            let member = message.mentions.members.first();
            member.roles.remove(member.roles.cache);
            }
        } else { message.reply('only admins can use the smacmedown command!:sob::sob:') }

Thanks for any help :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

.remove() returns a promise (Promise<GuildMember>). It will resolve with the member if the action was successful and reject with the error object on any kind of error. Handle the promise.

By simply adding a .catch() callback, the promise is handled and therefor does not throw an Unhandled promise rejection error

ALSO: The best way to remove all roles of a member is to do member.roles.set([]);

member.roles.set([])
   .then(member => /* On Success */)
   .catch(err => /* On Error */);

If you want to use Async/Await

try {
   await member.roles.set([]);

   /* ... On Success */
} catch (err) {
   /* On Error */
}

Here's the Documentation for GuildMemberRoleManager#remove() and GuildMemberRoleManager#set()

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