Reputation: 89
So I wrote the following code that is supposed to mute all the members in a given channel:
client.on('message', message => {
if (message.content == 'sh!') {
let channel = message.member.voice.channel
for (let member of channel.members) {
member[1].setMute(true)
}
}
})
But it does not work and I cannot find out why because I do not really know how the setMute() function works.
EDIT: I am not sure about how I can access every member and mute it
Upvotes: 0
Views: 338
Reputation: 728
The 'setMute' function is part of the member's voice state object. You're using it directly from the GuildMember object itself. As you may already know, the voice state object is the property 'voice' of the GuildMember object. So here's the solution:
// change this
member[1].setMute(true);
// to this
member[1].voice.setMute(true);
The property Members of a VoiceChannel is a Discord Collection (which extends from Javascript Map), I would iterate using a forEach loop so I could avoid Downlevel Iteration.
This should work:
client.on('message', message => {
if (message.content == 'sh!') {
const members = message.member.voice.channel.members;
members.forEach(member => {
member.voice.setMute(true);
});
}
});
Here's some useful links:
TextChannel#members | discord.js
Collection | discord.js
Map - JavaScript | MDN
Upvotes: 2