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

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

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 Relatório

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