-1

I have a problem with my code and try to find the error

I have already tried to use let instead of var but it still did not work. There is also no output in the console.

I believe the error to be within the if (tylerdel == true) of my code:

if (command === prefixfile.prefix + `active`) {
    var tylerdel = true
    message.channel.send (`test`)
    if (tylerdel == true) {
        if (message.author.id === ("")) {
            message.delete (1)
        }
    }
}

It is supposed to delete a message if it comes from a certain person but I also need it to be toggleable.

kalehmann
  • 4,821
  • 6
  • 26
  • 36

3 Answers3

1

As per your code boolean variable tylerdel will always be true so there is no need to use this variable in your if condition.

if(command === prefixfile.prefix + 'active') {
        message.channel.send('test');
        if (message.author.id === '') {
           message.delete(1);
        }
 }
Prabhat Kumar
  • 524
  • 5
  • 13
1

Be careful with == (Equality) and === (Identity). More info about the operators

You should know what is "Debugging". You can try printing something in each if to see where is the problem.

Hope this helps you to solve your problem.

AzmahQi
  • 378
  • 1
  • 15
-1

Try this:

if (command === prefixfile.prefix + 'active') {
    var tylerdel = true;
    message.channel.send ('test');
    if (tylerdel) {
        if (message.author.id === '') {
            message.delete(1);
        }
    }
}
José Matos
  • 569
  • 4
  • 13