Discord.js-我正在尝试创建一个discord bot,以使语音通道中的所有已连接成员静音

时间:2020-09-08 11:46:29

标签: javascript discord.js

我一直在尝试创建一个discord bot,该bot可以使某个语音通道的所有成员静音,该程序可以执行而不会出错,但是什么也没发生。

        let among_us_channel = message.guild.channels.cache.find(c => c.id === '751440430847098934');
        let group_of_channels = message.guild.channels.cache.find(c => c.id === '599377349531795471');
        const channels = message.guild.channels.cache.filter(c => c.parentID === '599377349531795471' && c.type === 2);


        for (const [channelID, channel] of channels) {
            for (const [memberID, member] of channel.members) {
                member.VoiceState.setMute(true, 'Game Started');
            }
        }

提前谢谢!

2 个答案:

答案 0 :(得分:0)

GuildMember没有名为VoiceState的属性,但是具有voice的属性VoiceState


for (const [channelID, channel] of channels) {
    for (const [memberID, member] of channel.members) {
        member.voice.setMute(true, 'Game Started');
    }
}

答案 1 :(得分:0)

如果您打算使单个频道的所有人静音,并且您不介意对其进行硬编码,则为id。然后就这么简单:

// Gets The Channel
const channel = message.guild.channels.cache.get(`channelId`);

// Iterate through it's members
channel.members.forEach(member => {
  member.voice.setMute(true); // Mute em'
});

无论如何,您似乎都想将类别中的每个频道设为静音。如果是这样,请尝试以下操作:

// Get the children of the category
const channels = message.guild.channels.cache.get(`categoryId`).children;

// Iterate through then
channels.forEach(channel => {
  if(channel.type === 'voice') {          // check if it is a voice channel
    channel.members.forEach(member => {   // Iterate through it's members
      member.voice.setMute(true);         // Mute em'
    });
  }
});