gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:08:07 25 4
gpt4 key购买 nike

我正在为我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com