1 回答
![?](http://img1.sycdn.imooc.com/533e4ce900010ae802000200-100-100.jpg)
慕工程0101907
TA贡献1887条经验 获得超5个赞
构造参数的一种简单方法是这样的:
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'
添加回答
举报
0/150
提交
取消