lost
lost

Reputation: 19

Discord.js — How to read all users in a voice channel and send a private message to each of them containing a random role

I want to make a Wolves/Mafia-esque game on my server. When I write the command !role 1wolf 2villagers, I would like to randomly distribute the specified roles by private message (so 1 person receives the wolf role and 2 people receive the villager role) to all the people in a specified voice channel.

The roles are not literal guild roles but simply a message.

Upvotes: 0

Views: 5288

Answers (1)

Androz2091
Androz2091

Reputation: 3005

You can do it easily:

client.on('message', (message) => {
    if(message.content.startsWith('!role')){
        let channelID = 'your voice channel id';
        message.guild.channels.get(channelID).members.forEach((member) => {
            member.send('Your role is villager!');
        });
    }
});

It will get the voice channels, and for each member, send a message to them.

Upvotes: 1

Related Questions