The Red Pill
The Red Pill

Reputation: 3

How do I exclude specific users from a discord server dm bot

I have a bot for a discord server that sends a dm to all of my server's members.

(The code is written in node.js.)

Reading the code, I cant figure out how to add an exception to skip over certain users in my server.

What would that line of code look like, would it need to interact with some other function in my bot's code?

I can provide you the code if that is necessary to understand my question.

Upvotes: 0

Views: 98

Answers (1)

Jakye
Jakye

Reputation: 6645

// Getting the guild by id.
const Guild = client.guilds.cache.get("GuildID");

/*
| Since Guild.members.cache is a Collection, you can use filter() to exclude certain members.
*/

const ExcludedMembers = ["UserID", "UserID", "UserID"];

const Members = Guild.members.cache.filter(member => !ExcludedMembers.includes(member.id));

/*
| The Members constant contains all the members in the guild, except for the ExcludedMembers.
| Now you can look through Members and send the message.
*/

Members.forEach((member, i) => {
    setTimeout(() => {
        member.send(`Hello, this is ${client.user.tag}!`).catch(e => console.error(`Couldn't send the message to ${member.user.tag}!`))
    }, i * 1000)
});

Upvotes: 1

Related Questions