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

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

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 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