问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/59804968/discord-js-how-to-read-all-users-in-a-voice-channel-and-send-a-private-message