javascript - 如何让你的机器人发送第二个参数
问题描述
like !L JohnGameRage#0000 将 L 给了 user#0000
解决方案
构造参数的一种简单方法是这样的:
let full = message.content.substr(1).trim(); //remove the prefix
let split = full.split(/ +/g); //seperate the words in the String and put them into an array
let cmd = split[0]; //the command is the first word in the array
let args = split.slice(1); //the arguments are all words except for the first one
在您的示例L
中将是命令,并且JohnGameRage#0000
将是第一个参数。
您可以像这样从数组中读取单个参数:
//Command = !L firstArg secondArg thirdArg fourthArg etc
cmd //returns 'L'
args[0] //returns 'firstArg'
args[1] //returns 'secondArg '
args[2] //returns 'thirdArg '
args[3] //returns 'fourthArg '
args[4] //returns 'etc'
推荐阅读
- azure-cosmosdb - 为什么不总是使用 EnableCrossPartitionQuery
- python-3.x - gcc 在 mac 上找不到标准库(从需求安装 python 包时)
- php - Laravel 调度程序未按预期工作
- http - 如何在 Apache Camel-Jersey Rest API 中获取 Http 标头值
- selenium - appium 问题,无法启动两个应用程序
- ios - iOS 12.2 是否支持用于 PWA 的 GPS?
- unit-testing - IntelliJ Idea - 跳转到覆盖代码的测试代码?
- performance - 基于 VICIDial IP 的配置.. 无外拨电话
- javascript - 有没有办法设置 SegmentPoints 和 Handles 的样式?
- php - 如果字段为空,则在以嵌入形式编辑父实体时删除子实体 - Symfony 4