• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

227
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();
almost 3 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();
almost 3 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.

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error