0

A friend was writing a discord bot using nodejs and ran into an issue where his condition:

client.on("messageCreate", msg => {
   if (msg.content == "Ash" || "ash") { 
     msg.reply("sample text");

Would always return as true, and the bot would reply to every message sent regardless of its content.

We managed to get around it by removing the ||, but I wasn't able to explain why it didn't work. I would appreciate it if anyone could help me.

  • 1
    client.on("messageCreate", msg => { if (msg.content == "Ash" || msg.content == "ash") { msg.reply("sample text"); } }); – Ann Francis Sep 14 '21 at 11:43
  • [Logical Or Operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR) – Elitezen Sep 14 '21 at 12:23
  • client.on("messageCreate", msg => { if (msg.content.toLowerCase() === "ash") { msg.reply("sample text"); } }) – Alixy Mizuki Sep 15 '21 at 05:45

0 Answers0