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

282
Vistas
Discord.js v13: how do I stop bot from targeting itself when trying to get a random member's profile picture?

I have this command to execute every day at 9 pm, but there is always a chance that my bot targets one of the two bots I have on my server with random(). How do I make it so it doesn't target them? perhaps there is a way to exclude members with a certain role since I have both bots with a role to separate them from the regular member list.

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 Respuestas
Responde la pregunta

0

We can do this in different ways, and some of them are:

Using the filter() JavaScript method:

// 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();

Using a while loop:

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

0

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

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

Basically what this does is it tries to get a random user from cache until it gets a non-bot user.

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