N
N
not important .2021-02-05 14:49:26
Node.js
not important ., 2021-02-05 14:49:26

How can I make "args" only be numbers?

Here is the code:

let messageArray = message.content.split(" ");
let args = messageArray.slice(1);

if(!args[0]) return client.send("Укажите цифру");

and when they write letters, it breaks, help me, I need to make sure that there are exactly numbers ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MamaLuyba, 2021-02-05
@26DiDi12

Not sure what is broken? A string arrives, it is transferred to an array by spaces, then a new array is returned without the first element. So what difference does it make if the array contains a number or a letter?
And so - through isNaN (element) you can check whether it is a number or not.
Well, in general - it's easier on the client to limit the input format, if possible.

A
Alex, 2021-02-05
@Kozack

https://developer.mozilla.org/uk/docs/Web/JavaScript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question