1
votes

I would have liked to add to my bot discord a feature to mutate everyone in a vocal lounge when I launch an order but I do not find how. My bot was programmed using Node.js with discord.js. Can someone help me? Thank you :)

My code :

const Discord = require("discord.js");

module.exports.run = async (client, message, args) => {
  if(!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("Vous n'\avez pas les permissions pour utiliser cette commande !");
  let voiceChannel =  message.guild.channels
  .filter(function (channel) { return channel.id === '540093524570406912' })
  .first()
  voiceChannel
  .join()
  .then(function (connection) {
      connection.members.setMute(true);
     })
}

module.exports.help = {
  name:"start"
}

Regards,

Quentin S

2

2 Answers

4
votes

setMute

client.on('message', (message) => {
    if (message.content == '/muteAll') {
        let channel = message.member.voiceChannel;
        for (let member of channel.members) {
            member[1].setMute(true)
        }
     }
});
1
votes

setMute is a method on GuildMember.voice (VoiceState) now. Documentation

client.on('message', (message) => {
    const channel = message.channel
    const members = channel.members
    if (message.content.startsWith("/muteall")) {
        members.forEach(member => {
            member.voice.setMute(true)
            member.voice.setDeaf(true)
        });
        message.channel.send('Server muted');
    } else if (message.content.startsWith("/unmuteall")) {
        members.forEach(member => {
            member.voice.setMute(false)
            member.voice.setDeaf(false)
        });
        message.channel.send('Server unmuted');
    }
});

I've created this bot for this https://github.com/Roshanjossey/discord-mute-voice-channel-bot