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

和自甴很熟 提交于 2020-06-01 04:38:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!