首页 > 解决方案 > 如何在 node.js 中使用startsWith?

问题描述

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 commands.")

以上是我尝试使用的示例.startsWith()。但是,我认为我没有正确使用它。
它会触发该消息,即使该消息确实包含Bot在其中。
控制台中没有记录错误。

标签: javascriptnode.jsdiscord.js

解决方案


startsWith是一个函数,您传递要检查的值,它将返回 a boolean,所以

if (botmod.startsWith("Bot")) 
  ...
} 

推荐阅读