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

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

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