问题描述
我需要一个代表任何数字的变量,我正在构建一个聊天机器人,对话的框架是对以数字方式表示的文档的请求,为此,我需要此变量,它可以检测到它是一个数字
if(message.body.includes(numberDocument)) {
client.sendMessage(message.from,'is the number of document: '+message.body);
}
numberDocument代表我的变量号,但是不起作用
var numberDocument = Number
解决方法
您可以使用正则表达式https://regexr.com/进行测试
Vect
这表示如果消息中有一个数字...,您还可以尝试检查消息中是否包含除数字以外的任何内容,否则返回错误
if(message.body.match(/\d/g) {
client.sendMessage(message.from,'is the number of document: '+message.body);
}
,
您可以使用正则表达式检查消息中是否包含数字。