node.js - Discordjs args 检查它是否是一个词
问题描述
我正在制作一个机器人来获取比特币价格并从不和谐中交换它。我想检查 args[0] 是否是一个数字,如果不是返回并发送消息。
if (!args.length){
return message.channel.send(`${message.author} You need to input arguments, example: -exchange 15000`);
}
const url = `https://blockchain.info/tobtc?currency=USD&value=${args[0]}`;
request(url, (err, res, body) => {
解决方案
- 使用
args[0]
而不是args.length
- 如果你使用
args
它if(args)
会返回一个布尔值 - 所以你的代码应该是这样的:
if (!args[0]){
return message.channel.send(`${message.author} You need to input arguments, example: -exchange 15000`);
}
推荐阅读
- emv - 解释 EMV MDK 密钥 Enc MAC AC
- javascript - 引导表跟随 div 内的滚动
- angular - 在按钮单击时选择 PrimeNg 多选选项,Angular
- javascript - Javascript Regex - 从标签字符串中获取特定的 html 标签
- java - 未经授权的用户访问某些 url
- symfony - Symfony 异常 - 目录不可写
- amazon-web-services - 在 AWS SDK 中同时处理多个用户
- python - java.lang.NoSuchFieldError: DECIMAL128 mongoDB spark
- regex - 如何在python中的字符串中找到确切的单词
- android - 我如何从android中的服务器获取数据