I
I
Ilya Zholudev2021-05-25 15:27:08
Node.js
Ilya Zholudev, 2021-05-25 15:27:08

Why can't I find the number I need in the message?

And so, good afternoon.

My main problem is that my code can't recognize the numbers in message:

if (message.content.split("1")) { points = 10; console.log("first rule"); }
        else if (message.content.split("2")) { points = 10; console.log("second rule"); }
        else if (message.content.split("3")) { points = 20; console.log("third rule"); }
        else if (message.content.split("4")) { points = 20; }

It would seem that everything is fine, but I put console.log here for a reason. The thing is, when I write my command,
it can never find the number and instead the first if is always executed.

For example, I write the command /warn @User 3
What I just didn’t try and .includes("3"), .slice("3") , message.content === "3". And nothing.
Nothing causes the third if.
Likewise with the rest.

What could be the reason?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Keppp, 2021-05-25
@Keppp

60acf7c2a1362211897552.png
It seems that everything works through includes)

I
Ilya Zholudev, 2021-05-25
@Astroreen

message.content included one in the person's id, which is why the first if always worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question