我正在尝试创建一个机器人,该机器人通过向其添加“ TempMute”角色来使当前处于语音通道中的每个人静音。然后,当我发送/ unmuteAll时,我希望具有“ TempMute”标签的每个人都删除该标签。我尝试了几种不同的方法,但均未成功。我正在使用discord.js版本12.2.0。
const Discord = require('discord.js');
voiceChatChannelId="123456789"
bot.on('message', (message) => {
var vc = bot.channels.cache.get(voiceChatChannelId);
if (message.content == '/muteAll') {
for (let member of vc.members){
//add members all to "TempMute" role
}
}
else if (message.content == '/unmuteAll') {
for (let member of vc.members){
//remove ALL members from role "TempMute"
}
}
});
答案 0 :(得分:0)
由于您已经拥有GuildMember
,因此可以使用GuildMember.roles
.add
或GuildMember.roles
.remove
方法来添加或删除角色。
bot.on('message', (message) => {
var vc = bot.channels.cache.get(voiceChatChannelId);
if (message.content == '/muteAll') {
for (let member of vc.members.array()){
//add members all to "TempMute" role
member.roles.add("RoleID")
}
}
else if (message.content == '/unmuteAll') {
for (let member of vc.members.array()){
//remove ALL members from role "TempMute"
member.roles.remove("RoleID")
}
}
});