侦听多个命令 [英] Listen for multiple commands in a case
本文介绍了侦听多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取它,以便当用户说出诸如'!help'或'!commands'之类的命令时,它返回帮助消息,以便节省代码中的空间并且不使用2种情况,我把它变成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;
};
};
这篇关于侦听多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文