Reputation: 19
This is the code I use to count members with a specific role whom are in a voice channel. I want to send a private message to members with the role and not in a voice channel. How can I do so?
var takaci = 0;
let a = client.guilds
.get(sunucuid)
.roles.get(rolid)
.members.filter(o => o.voiceChannel).size;
let ses = a;
Upvotes: 0
Views: 60
Reputation: 5623
Inverse your predicate function in Collection.filter()
to acquire only those members with the role and not in a voice channel. Use the !
character, or logical NOT operator.
Iterate over your Collection.
Use GuildMember.send()
to send a direct message to each member individually.
const membersToMsg = client.guilds.get(sunucuid).roles.get(rolid).members.filter(m => !m.voiceChannel);
for (const [, member] of membersToMsg) {
member.send('Hello, world!')
.catch(console.error); // 'Cannot send messages to this user' is most likely due to privacy settings
}
I'm using a for...of
loop in this code rather than Map.forEach()
because the latter will simply fire promises and move on, possibly resulting in uncaught rejections.
Upvotes: 1