• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

203
Views
How to use multiple word in "startsWith"
if (message.content.startsWith('let', 'Let')){/do something/})

I want bot work when user type "let" or "Let", but it can just work when "let" typed How to fix this? Thanks for helping

almost 3 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You could use regular expressions here:

var terms = ["let", "Let"];
var regex = new RegExp("^(?:" + terms.join("|") + ")\\b");
var inputs = ["Let it be!", "let it be!", "Green Eggs and Ham"];
for (var i=0; i < inputs.length; ++i) {
    if (regex.test(inputs[i])) {
        console.log("MATCH    => " + inputs[i]);
    }
    else {
        console.log("NO MATCH => " + inputs[i]);
    }
}

To be clear, we are using test() with the regex pattern:

^(?:let|Let)\b

You may add more terms to the above alternation as needed.

almost 3 years ago · Juan Pablo Isaza Report

0

To keep things flexible you could keep an array of words you want to check, and then use some to check to see if any of those words are at the beginning of the content string.

const words = ['let', 'Let', 'Bob'];

const message1 = { content: 'let' };
const message2 = { content: 'notlet' };
const message3 = { content: 'Let' };
const message4 = { content: 'Bob' };

function startsWith(message) {
  return words.some(word => {
    return message.content.startsWith(word);
  });
}

console.log(startsWith(message1));
console.log(startsWith(message2));
console.log(startsWith(message3));
console.log(startsWith(message4));

almost 3 years ago · Juan Pablo Isaza Report

0

I believe you are looking for case insensitive match. In that case following can work assuming your message.content is a string or object.
Here we collect user typed string in userTypedThis variable.

if (message.content.toString().toLowerCase().startsWith(
   userTypedThis.toString().toLowerCase())
){/do something/})
almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error