Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  129] [ 7]  / answers: 1 / hits: 26813  / 4 Years ago, tue, july 14, 2020, 12:00:00

I'm working on a discord bot for my friend group's gaming server. I'd like to add a command 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!


More From » discord

 Answers
4

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


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


// Your invokation here, for example your switch/case hook for some command (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!');
}

[#50805] Sunday, July 5, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarrodfletchers

Total Points: 75
Total Questions: 94
Total Answers: 95

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
jarrodfletchers questions
Sat, Sep 25, 21, 00:00, 3 Years ago
Mon, Jan 21, 19, 00:00, 5 Years ago
Sun, Dec 16, 18, 00:00, 6 Years ago
Sun, Nov 4, 18, 00:00, 6 Years ago
;