1 回答

TA貢獻1887條經(jīng)驗 獲得超5個贊
構(gòu)造參數(shù)的一種簡單方法是這樣的:
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將是第一個參數(shù)。
您可以像這樣從數(shù)組中讀取單個參數(shù):
//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'
添加回答
舉報