我正在尝试获取它,以便当用户说出诸如!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模板网!
discord.js v12:我如何等待 DM 频道中的消息?discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 频道中的消息?)
如何让我的机器人提及发出该机器人命令的人how to make my bot mention the person who gave that bot command(如何让我的机器人提及发出该机器人命令的人)
如何修复必须使用导入来加载 ES 模块 discord.jsHow to fix Must use import to load ES Module discord.js(如何修复必须使用导入来加载 ES 模块 discord.js)
如何列出来自特定服务器的所有成员?How to list all members from a specific server?(如何列出来自特定服务器的所有成员?)
Discord bot:修复“找不到 FFMPEG"Discord bot: Fix ‘FFMPEG not found’(Discord bot:修复“找不到 FFMPEG)
使用 discord.js 加入 discord 服务器时的欢迎消息Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服务器时的欢迎消息)