let botmod = staff.get(`${message.author.id}`)
if (botmod.startsWith !== "Bot")
return message.channel.send("Unfortunately, you are a server mod. You can't use bot mands.")
The above is an example of me trying to use .startsWith()
. However, I don't think I am using it correctly.
It triggers that message, even if the message does have Bot
in it.
There are no errors logged in the console.
let botmod = staff.get(`${message.author.id}`)
if (botmod.startsWith !== "Bot")
return message.channel.send("Unfortunately, you are a server mod. You can't use bot mands.")
The above is an example of me trying to use .startsWith()
. However, I don't think I am using it correctly.
It triggers that message, even if the message does have Bot
in it.
There are no errors logged in the console.
-
There's not enough in your post to provide an answer since there's no way to tell what
staff.get
returns; however,String.prototype.startsWith
is a method and needs parentheses. – benbotto Commented Sep 8, 2020 at 22:45 - Documentation is always your friend developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – sinanspd Commented Sep 8, 2020 at 22:46
3 Answers
Reset to default 3startsWith is a function, you pass the value you want to check and it will return a boolean
, so
if (botmod.startsWith("Bot"))
...
}
It is a function:
If you want the string to start with Bot,
if(botmod.startsWith("Bot")){
// ...do stuff
}
or If you don't want the string to start with Bot,
if(!botmod.startsWith("Bot")){
// ...do stuff
}
However, you can only run .startsWith()
on Strings.
startsWith returns a boolean. So you want
const foo = 'bar';
if(foo.startsWith('thing')) {
// do stuff
}