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

271
Views
Discord.js v13: ¿cómo evito que el bot se dirija a sí mismo cuando intento obtener la imagen de perfil de un miembro al azar?

Tengo que ejecutar este comando todos los días a las 9 p. m., pero siempre existe la posibilidad de que mi bot apunte a uno de los dos bots que tengo en mi servidor con random(). ¿Cómo hago para que no los apunte? tal vez haya una manera de excluir a los miembros con un determinado rol, ya que tengo ambos bots con un rol para separarlos de la lista de miembros regulares.

 let KillerMessage = new cron.CronJob('00 00 21 * * *', () => { //seconds, minutes, hours, month, day of month, day of week const guild = client.guilds.cache.get('ID'); const channel = guild.channels.cache.get('ID'); const user = client.users.cache.random(); //random user const exampleEmbed = new MessageEmbed() .setColor('#0099ff') .setTitle(`The BLACKENED for this trial is: ${user.username}`) .setImage(user.displayAvatarURL()) channel.send({ embeds: [exampleEmbed] }); }); KillerMessage.start();
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esto lo podemos hacer de diferentes maneras, y algunas de ellas son:

Usando el método de JavaScript filter() :

 // Get the cache users list and filter the users that aren't a bot, creating a new array with only non-bot users. let user = client.users.cache.filter(user => !user.bot).random();

Usando un bucle while :

 // This loop randomizes again, until the chosen user is not a bot. let user = client.users.cache.random(); while (user.bot) user = client.users.cache.random();
about 4 years ago · Juan Pablo Isaza Report

0

let user = client.users.cache.random(); while (user.bot) user = client.users.cache.random();

Básicamente, lo que hace es intentar obtener un usuario aleatorio del caché hasta que obtiene un usuario que no es bot.

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!