Brandon
Brandon

Reputation: 63

How to make an if statement work if a message starts the prefix + a command using discord.js

Hello I've switched from working with discord.py to discord.js for my discord bot. Im having trouble currently, i want a feature of my bot to be able to be given a sentence beginning with a command and prefix (for example *say Hello world) then I want the bot to remove the prefix and command and send the rest of the content back.

However I can't seem to get the if statement to work vie tried this

if (msg.content.startsWith == prefix + 'say')

which is similar to pythons syntax but doesn't seem to trigger if I use this, I want to be able to type something like this (*say hello world) and the if statement should trigger because the first thing in the message is the command, however it doesn't work

Upvotes: 0

Views: 733

Answers (1)

Syntle
Syntle

Reputation: 5174

startsWith is not a property, it's a function.

You can achieve your goal by either using startsWith()

if (msg.content.startsWith(`${prefix}say`))

Or you can just check if the message.content is equal to ${prefix}say

if (msg.content === `${prefix}say`)

Upvotes: 2

Related Questions