简体   繁体   中英

Mute everyone in a voice channel with a Discord Bot with Discord.js

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

setMute

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

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

创建一个没有发言权限的角色,并将其添加到您频道中的所有用户。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM