javascript - 静音整个 Discord 语音 channel (JS)

标签 javascript discord bots discord.js

我正在为我的 friend 组的游戏服务器开发一个不和谐的机器人。我想添加一个命令,使语音 channel 中的每个人都静音。我想这 msg.member.voice.channel.members.setmute(true);会工作,但它返回不是一个函数并使机器人崩溃。这个msg.member.voice.setMute(true);就像它一样,它将服务器静音发送消息的成员,但显然不是我想要的整个 channel 。我是 discord.js 的新手,文档有点困惑。谢谢你的时间!

最佳答案

不久前,我在一个项目中做了类似的事情,我不得不让除了发出命令的人之外的所有人都静音。
您可以通过遍历当前 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!');
}

关于javascript - 静音整个 Discord 语音 channel (JS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62887805/

相关文章:

python - 由于EnvironmentError无法安装 `discord.py`

javascript - 在 Slack Nestor 机器人回复中调用 giphy 搜索

azure - Bot 框架编写器无法发布到 Azure LUIS 错误

javascript - 图库中的图像在 IE 中不显示

javascript - jQuery 向每一行的下一列添加附加值

javascript - 如何让这个动画从右向左移动?

javascript - Discord.js 存在事件状态和名称存在问题

javascript - 将函数 react 组件转换为 react 类以添加 ref 属性

python - Discord.py Killswitch

javascript - Discord.js Ping 号码的问题