Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
¿Por qué bulkDelete no funciona sin ningún error?

Intenté buscar errores tipográficos y otras inexactitudes e intenté agregar el requisito de permiso para el comando de podar, pero aún así, las respuestas de ping pong y "no es un número válido" funcionan, pero no la poda cuando ingreso la cantidad.

Detalles: Estoy tratando de hacer un bot de Discord que pueda podar según la entrada. Uso DJS v12 y sigo esta guía 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 answers
Answer question

0

La razón por la que su comando de podar no funciona es debido al análisis de su comando. args siempre es null , mientras que cmd siempre contiene la cadena completa.

Entonces, si ingresa $prune 3 , sus args estarán vacíos y cmd contiene prune 3 . Por eso tu if aquí:

 else if (cmd === `prune`)

no coincide (si especificó argumentos) y su comando de podar nunca se ejecuta.

Para solucionar eso, ha cambiado el análisis de su comando:

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

Nota: También parece que tiene un error tipográfico en su pregunta:

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

Así que cambia esa línea a

 if (!msg.guild.me.hasPermission("MANAGE_MESSAGES")) return;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!