admin管理员组

文章数量:1289565

I'm working on a discord bot for my friend group's gaming server. I'd like to add a mand mutes everyone in the voice channel. I figured that this msg.member.voice.channel.members.setmute(true); would work but it's returning back not being a function and crashes the bot. This msg.member.voice.setMute(true); works as in it will server mute the member who sends the message but obviously not the whole channel which is what I'm going for. I'm brand new to discord.js and the documentation has been a little confusing. Thanks for your time!

I'm working on a discord bot for my friend group's gaming server. I'd like to add a mand mutes everyone in the voice channel. I figured that this msg.member.voice.channel.members.setmute(true); would work but it's returning back not being a function and crashes the bot. This msg.member.voice.setMute(true); works as in it will server mute the member who sends the message but obviously not the whole channel which is what I'm going for. I'm brand new to discord.js and the documentation has been a little confusing. Thanks for your time!

Share Improve this question asked Jul 14, 2020 at 3:54 jpzkjpzk 431 gold badge1 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

I did something similar in a project not too long ago where I had to mute everyone but the person issuing the mand.

You can acplish this by iterating through an array of all users in the current channel.

// Your invokation here, for example your switch/case hook for some mand (i.e. '!muteall')
// Check if user is in a voice channel:
if (message.member.voice.channel) {
  let channel = message.guild.channels.cache.get(message.member.voice.channel.id);
  for (const [memberID, member] of channel.members) {
    // I added the following if statement to mute everyone but the invoker:
    // if (member != message.member)

    // This single line however, nested inside the for loop, should mute everyone in the channel:
    member.voice.setMute(true);
  }
} else {
  message.reply('You need to join a voice channel first!');
}

本文标签: javascriptMuting an Entire Discord Voice Channel (JS)Stack Overflow