Listen for multiple commands in a case(在一个案例中监听多个命令)
问题描述
我正在尝试获取它,以便当用户说出诸如!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;
};
};
这篇关于在一个案例中监听多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在一个案例中监听多个命令
基础教程推荐
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
