1

Im making a bot that prevents users from talking about age, but i have the problem, that i don't know how to solve. If a user inputs "i am (number)" it should reply with " Don't talk about age here!". This is my code (the part i need help with).

var age = ['how old', 'how old am i', 'how old are you', `i am ${!NaN}`];

if (age.includes(message.content)) {
    message.reply('Don't talk about age here!')
}

i am ${!Nan} should be any number but it doesn't work.

2

2 Answers 2

1

For the regex you might wanna try something like so :

var age = ['how old', 'how old am i', 'how old are you', 'i am 10'];

if (age[3].match(/(\d+)/)!=null) {
    console.log("Don't talk about age here!")
}

Sign up to request clarification or add additional context in comments.

Comments

1

You can use a regular expression to look for digit (number) characters in the input string.

const containsNumber = (str) => /\d/.test(str)

const result1 = containsNumber('I am 25 years old.')
console.log(result1) // true

const result2 = containsNumber('My age is a secret.')
console.log(result2) // false

And the template literal syntax is as follows:

const myAge = 39
const myString = `I am ${myAge} years old.`
console.log(myString)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.