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

275
Views
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 answers
Answer question

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 Report

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