javascript - How to use startsWith in node.js? - Stack Overflow

let botmod = staff.get(`${message.author.id}`)if (botmod.startsWith !== "Bot")return message.

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.

Share Improve this question edited Sep 9, 2020 at 8:01 Mineko Kayui 7614 silver badges15 bronze badges asked Sep 8, 2020 at 22:42 Magical CatMagical Cat 781 silver badge8 bronze badges 2
  • 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
Add a ment  | 

3 Answers 3

Reset to default 3

startsWith 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
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744336949a4569171.html

相关推荐

  • javascript - How to use startsWith in node.js? - Stack Overflow

    let botmod = staff.get(`${message.author.id}`)if (botmod.startsWith !== "Bot")return message.

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信