本文介紹了在一個案例中監聽多個命令的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試獲取它,以便當用戶說出諸如!help"或!commands"之類的命令時,它會返回幫助消息,以節省我的代碼空間而不是使用兩種情況,怎么能我把它變成1?
I'm trying to get it so that when a user says a command like '!help' or '!commands' it returns the help message, in order to save space in my code and not use 2 cases, how can I make this into 1?
client.on('message', message => {
let args = message.content.substring(prefix.length).split(" ");
switch (args[0]) {
case ('help' || 'commands'):
我不知道該怎么做,它會響應幫助";但不是命令.有什么想法嗎?
I'm not sure what to do, it responds to "help" but not to commands. Any ideas?
推薦答案
switch
語句有一個特性,可以創建一個空的case
.如果 case
返回 true,它將簡單地執行下一個帶有代碼的 case
語句.
The switch
statement has a feature where you can create an empty case
. If the case
returns true, it will simply execute the next case
statement with code.
switch ('someString') {
case 'someString':
case 'someOtherString': {
console.log('This will still execute');
break;
};
};
這篇關于在一個案例中監聽多個命令的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!