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