我使机器人具有以下代码的前缀:
if(msg.author.bot || !msg.content.startsWith(cfg.prefix))
return;
防止僵尸程序和僵尸程序不得不专注于不一致的每个书面文本。
我的问题或要求是,如果有一个特定的单词以不和谐的形式编写而没有前缀,那么我应该如何实现呢?
示例:Bot将显示为:
>command
(“>”是前缀)
我应该如何使bot读取前缀和不带前缀的命令?
示例:Bot可以读取每个前缀,并且该命令没有前缀:
command that has no prefix
答案 0 :(得分:0)
编辑: 抱歉,误解了您的问题,在这种情况下,您需要使用以下内容:
// if the author is bot exit immediately
if (msg.author.bot) return;
if (
msg.content.startsWith(prefix)
) switch (
msg.content.substr(msg.content.indexOf(prefix)) // this just removes the prefix from the beggining of the command
) {
case "cmd_with_prefix0":
...
break;
case "cmd_with_prefix1":
...
break;
} else switch (msg.content) {
case "cmd_without_prefix0":
...
break;
case "cmd_without_prefix1":
...
break;
}
这将与所有这些匹配:
>cmd_with_prefix0
>cmd_with_prefix1
cmd_without_prefix0
cmd_without_prefix1
假设prefix
是>