elm
elm

Reputation: 53

how to make if (message.content.startsWith('')) detect for 2 things

So I have the code

if (message.content.startsWith('')) 

in my script and I want it to make it so it goes through if it is uppercase OR lowercase. I tried

if(message.content.startsWith('>command', '>COMMAND')) 

but that didn't work. Can someone tell me the correct code?

Upvotes: 3

Views: 1694

Answers (2)

Pranav C Balan
Pranav C Balan

Reputation: 115222

Use RegExp#test with RegExp ^>command(where ^ is start anchor) and flag i for ignoring case.

if(/^>command/i.test(message.content)))

Upvotes: 0

Code Maniac
Code Maniac

Reputation: 37755

You can change the value to lowercase first before matching

message.content.toLowerCase().startsWith(">command")

You can use search

message.content.seach(/^>command/i)

Upvotes: 2

Related Questions