为了账号安全,请及时绑定邮箱和手机立即绑定

你怎么能让你的机器人发送第二个参数

你怎么能让你的机器人发送第二个参数

开心每一天1111 2021-11-18 20:25:21
就像 !L JohnGameRage#0000 已经把 L 给了 user#0000
查看完整描述

1 回答

?
慕工程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'


查看完整回答
反对 回复 2021-11-18
  • 1 回答
  • 0 关注
  • 138 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信