madladzen
madladzen

Reputation: 91

Why is my discord.js bot not responding to ";say (content)"

I am coding a bot on discord called LowerBot, it is made in javascript and is using npm and discord.js. If somebody can pinpoint exactly where my bot went wrong that would be nice.

Here is my code:

function getAfterSpace(str) {
    return str.split(' ')[1]; // get after space
}
client.on("message", msg => {
    if (msg.content.toLowerCase().includes === ";say ") {
        msg.channel.send(`${getAfterSpace(msg.content)}`)
    }
})

Upvotes: 0

Views: 56

Answers (2)

Hibatica
Hibatica

Reputation: 1

There are many ways to do it, but this is what I would do:

if(message.content.toLowerCase.StartsWith(";say") {
   let result = message.content.split(" "); // creates an array of each word
   result = result.slice(1); // removes first entry (";say");
   result = result.join(" "); // combines each object in the array into a string. each object is separated by a space.
}

Upvotes: 0

Karl-Johan Sjögren
Karl-Johan Sjögren

Reputation: 17532

Because includes is a method and you are comparing against the method actual method and not an invocation of it.

It should be msg.content.toLowerCase().includes(";say ") instead.

Upvotes: 2

Related Questions