如何让 args 只读某些单词

how to make args only read certain words

我正在编码一个不和谐的机器人,我需要一个命令的帮助我正在编码:sr!coin 这是代码:

        case "coin":
      if (args[1] === "heads", "tails") {
        message.channel.sendMessage(`Your bet: ${args[1]}, outcome: ${coins[Math.floor(Math.random() * coins.length)]}`);
      } else {
        message.channel.sendMessage('Your arguments must include of sr!coin heads or sr!coin tails!');
      }

它不输出任何错误,只接受除头部和尾部之外的其他参数

此语句 if (args[1] === "heads", "tails"){...} 没有按照您的要求执行。

我想你正在寻找:

if (args[1] === "heads" || args[1] === "tails"){....}

什么是args?是 process.argv.slice(2) 吗?如果是,请执行:

if (['heads','tails'].includes(args[1]))