我正在制作一个阻止用户谈论年龄的机器人,但我有一个问题,我不知道如何解决。如果用户输入“我是(数字)”,它应该回复“不要在这里谈论年龄!”。这是我的代码(我需要帮助的部分)。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!')}我是 ${!Nan} 应该是任何数字,但它不起作用。
3 回答
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
对于正则表达式,您可能想尝试这样的事情:
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!")
}
拉莫斯之舞
TA贡献1820条经验 获得超10个赞
您可以使用正则表达式在输入字符串中查找数字(数字)字符。
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
模板文字语法如下:
const myAge = 39
const myString = `I am ${myAge} years old.`
console.log(myString)
添加回答
举报
0/150
提交
取消
