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

361
Vistas
Discord.js v13 How to prevent mod commands from working on mods?

So I wanted to make a mute command for my Discord bot. It is supposed to mute a mentioned user untill they are unmuted through another command (WIP), additionaly there should be an option to give a reason. If there is no reason provided it just says Reason: none. I've managed to Restrict the command acces to a mod role (although in the following code it checks for the MODERATE_MEMBERS flag, because that's a better way to do it imo) and made it return all the required Error messages like "I can't mute that user" and such. Here's my code:

const { Permissions } = require('discord.js');

module.exports = {
    name: 'mute',
    description: "Mutes a user for an unlimited amount of time.",
    execute(message, args)
    {
        const target = message.mentions.members.first();
        let muteReason = args.join(" ").slice(22);

        if(message.member.permissions.has(Permissions.FLAGS.MODERATE_MEMBERS))
        {
            if(target)
            {
                if(target.id == '943093289031176203')
                {
                    message.reply("I can't mute myself.")
                }
                else if(message.member == target)
                {
                    message.reply("You can't mute yourself!")
                }
                else if(target.permissions.has(Permissions.FLAGS.MODERATE_MEMBERS))
                {
                    if(!muteReason)
                    {
                        muteReason = "None"
                    }
                    let muteRole = message.guild.roles.cache.find(role => role.name === "muted");
                    let memberTarget = message.guild.members.cache.get(target.id);

                    memberTarget.roles.add(muteRole.id);
                    message.reply(`<@${memberTarget.user.id}> has been muted. Rason: ` + muteReason);
                }
                else
                {
                    message.reply("I can't mute that user.")
                }
            
            }
            else
            {
                message.reply("You have to mention a valid member of this server.")
            }
        }
        else
        {
            message.reply("You can't use that.")
        }
       
    }
}

The problem I'm having is that moderators can mute other moderators which shouldn't happen. So basically I need a solution that makes the command not work on other people who have a mod role or a command that doesn't work on people with certain permissions (preferably the 2nd one since it's gonna be more usefull).

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could check for moderator permissions on the specified user, then only mute if the user doesn't have the permission. This way it won't allow mods to be muted.

//...

  let memberTarget = message.guild.members.cache.get(target.id);

  if (memberTarget.permissions.has(Permissions.FLAGS.MODERATE_MEMBERS)) {
    message.reply(`<@${memberTarget.user.id}> is a Moderator. You cant' mute them.`);
  } else {
    memberTarget.roles.add(muteRole.id);
    message.reply(`<@${memberTarget.user.id}> has been muted. Reason: ` + muteReason);
  }

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