Discord bot 命令错误

时间:2021-05-25 23:47:14

标签: javascript discord discord.js

请帮我找出为什么这不起作用:

client.on("message", (message) => {
    const channel = message.channel
    const members = channel.members
    if (message.content.startsWith(prefix + "muteall")) {
        message.guild.channels.cache.filter((c) => c.type == "voice").forEach((voicechannel) => {

              voicechannel.members.forEach((x) => {
                member.voice.setMute(true)
                member.voice.setDeaf(true)
              });

            });
            return message.channel.send("Svi su mutovani!")
}
  });
  client.on("message", (message) => {
    if (message.content.startsWith(prefix + "unmuteall")) {
        message.guild.channels.cache.filter((c) => c.type == "voice").forEach((voicechannel) => {

              voicechannel.members.forEach((x) => {
                member.voice.setMute(false)
                member.voice.setDeaf(false)
              });

            });
            return message.channel.send("Svi su unmutovani!")
}
  });

机器人可以工作,但在调用取消静音命令后,它崩溃并出现以下错误:

Cannot read property 'setMute' of undefined

1 个答案:

答案 0 :(得分:2)

在您的 forEach 回调中,您将成员命名为 x,但尝试访问 member

您需要将 (x) => { 替换为 (member) => {