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!
1 Answer
Reset to default 5I 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
版权声明:本文标题:javascript - Muting an Entire Discord Voice Channel (JS) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741450735a2379472.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论