替代message.content.startsWith

``````if(message.content.startWith(`\${prefix}help`))
``````

``````if(message.content.startWith(`\${prefix}help 2`))
``````

If i do `>help 2` I get both. Is there any way to stop that from happening?

• 逗妇乳 回复

When using `startsWith(">help")` (not startWith) it will match ">help 2" because that string does indeed start with ">help". If you want to match these cases more precisely you should put the most specific cases first and use `else if` for subsequent comparisons.

``````if (message.content.startsWith(`\${prefix}help 2`)) { /* do stuff */ }
else if (message.content.startsWith(`\${prefix}help`)) { /* do other */ }
``````

如果第一种情况不匹配，则上面的代码将仅与第二种情况匹配。