Stevan
Stevan

Reputation: 1

Discord bot command bug

Please help me id why this doesn't work:

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!")
}
  });

The bot works but after the unmute command is called it crashes and gives this error:

Cannot read property 'setMute' of undefined

Upvotes: 0

Views: 70

Answers (1)

Seblor
Seblor

Reputation: 7136

In your forEach callback, you are naming the member x, but attempting to access member.

You need to replace (x) => { with (member) => {

Upvotes: 2

Related Questions