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

220
Vistas
Why does bulkDelete not work with no error?

I've tried to look for typo and other inaccuracies and tried to add permission requirement for the prune command but still, the ping pong and the "not a valid number" replies work but not the prune when I enter the amount.

Details: I'm trying to make a Discord bot that can prune based on input. I use DJS v12 and follow(ed) this guide https://v12.discordjs.guide/creating-your-bot/commands-with-user-input.html#number-ranges

if (!msg.content.startsWith(prefix) || msg.author.bot) return;
if (!msg.member.hasPermission("BAN_MEMBERS")) {
  msg.channel.send("You don\'t have permission.");
}
const args = msg.content.slice(prefix.length).trim().split('/ +/');
const cmd = args.shift().toLowerCase();
  if (cmd === `ping`) {
    msg.reply('pong.');
  } else if (cmd === `prune`) {
    if (!msg.guild.me.hasPermission("MANAGE_MESSAGES")) return;
    const amount = parseInt(args[0]) + 1;
    
    if (isNaN(amount)) {
      return msg.reply('Not a valid number.');
    } else if (amount <= 1 || amount > 100) {
      return msg.reply('Please input a number between 1 and 99.');
    }
  msg.channel.bulkDelete(amount, true).catch(err => {
        console.error(err);
        msg.channel.send('Error!');
   });
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The reason why your prune command doesn't work, is because of your command parsing. args is always null whereas cmd always contains the whole string.

So if you enter $prune 3, your args will be empty and cmd contains prune 3. That's why your if here:

else if (cmd === `prune`)

doesn't match (if you specified arguments) and your prune command never gets executed.

To fix that, you have change your command parsing:

const cmd = msg.content.split(" ")[0].slice(prefix.length);
const args = msg.content.split(" ").slice(1);

Note: Also you seem to have a typo in your question:

if (!msg.guild.me.hasPermission("MANAGE_MESSAGES") return;
//                           Missing ")" here ----^

So change that line to

if (!msg.guild.me.hasPermission("MANAGE_MESSAGES")) return;
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