0
        case 'ping' || 'Ping': {
      message.reply('PONG!');
    }

    break;


    // Kick



  case 'kick' || 'Kick':
    const user = message.mentions.users.first();
      if (user) {
          const member = message.guild.member(user);
          if (member) {
              member
                  .kick('Bad Boi')
                  .then(() => {
                      const Embed = new MessageEmbed()
                          .setTitle(`Kick Results`)
                          .setColor(0xff0000)
                          .setDescription(`${user.tag} has been kicked!`)
                      message.channel.send(Embed);
                      const Embed3 = new MessageEmbed()
                      .setTitle(`Warn Results`)
                      .setColor(0xff0000)
                      .setDescription(`You have been banned! by ${message.author}`)
                      user.send(Embed3)
                  }).catch(err => {
                      message.reply('I was unable to ban the member');
                      console.log(err);
                  })
          } else {
              const Embed = new MessageEmbed()
                  .setTitle(`Error`)
                  .setColor(0xff0000)
                  .setDescription('That user isn\'t in the guild!')
              message.channel.send(Embed);
          }
      } else {
          const Embed = new MessageEmbed()
              .setTitle(`Error`)
              .setColor(0xff0000)
              .setDescription('That user isn\'t in the guild!')
          message.channel.send(Embed);
    }
    break;



    // Ban 



  case 'ban' || 'Ban':
      if (user) {
          const member = message.guild.member(user);
          if (member) {
              member
                  .ban({
                      reason: 'Bad Boi'
                  })
                  .then(() => {
                      const Embed = new MessageEmbed()
                          .setTitle(`Ban Results`)
                          .setColor(0xff0000)
                          .setDescription(`${user.tag} has been banned!`)
                      message.channel.send(Embed);
                      message.channel.send(Embed);
                       const Embed2 = new MessageEmbed()
                      .setTitle(`Warn Results`)
                      .setColor(0xff0000)
                      .setDescription(`You have been banned! by ${message.author}`)
                      user.send(Embed2)
                  }).catch(err => {
                      message.reply('I was unable to ban the member');
                      console.log(err);
                  })
          } else {
              const Embed = new MessageEmbed()
                  .setTitle(`Error`)
                  .setColor(0xff0000)
                  .setDescription('That user isn\'t in the guild!')
              message.channel.send(Embed);
          }
      } else {
          const Embed = new MessageEmbed()
              .setTitle(`Error`)
              .setColor(0xff0000)
              .setDescription('That user isn\'t in the guild!')
          message.channel.send(Embed);
    }

    break;


    // Warn

  case 'warn' || 'Warn': {
    if (user) {
      const Embed = new MessageEmbed()
        .setTitle(`Warn Results`)
        .setColor(0xff0000)
        .setDescription(`${user.tag} has been warned!`)
      message.channel.send(Embed);
      const Embed1 = new MessageEmbed()
        .setTitle(`Warn Results`)
        .setColor(0xff0000)
        .setDescription(`You have been warned! by ${message.author}`)
      user.send(Embed1)
    }
  }

  break;
  

  }
})

I cant fix this error and its frustrating. Please help me it will be very appreciated. I only referenced the user once because it would break the other code however it was working fine before and now it's breaking.

Also if you do help please leave an explanation of my error so I don't need to ask again!

The warn-code block is failing

Gavin_NA
  • 1
  • 2
  • Hi interesting, does the stack trace say which line is failung? – IronMan Sep 28 '20 at 20:17
  • Yes, It is under the warn-code block that is failing – Gavin_NA Sep 28 '20 at 20:19
  • Either put `const user = message.mentions.users.first();` (in your kick command) outside of the `switch` block, or put braces (`{}`) around the kick and warn commands and put `const user = ...` in the warn command. See [this answer](https://stackoverflow.com/a/50753272/8289918) for info on lexical declarations (`const`, `let` etc.) in case blocks. – Lauren Yim Sep 29 '20 at 01:38

0 Answers0