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'
添加回答
舉報
0/150
提交
取消