首页 > 解决方案 > javascript不和谐不区分大小写错误

问题描述

我是 JavaScript 新手。我正在制作一个不和谐的机器人,但我总是收到错误消息,说message.startsWith is not a function原因是我不想让机器人聊天响应不区分大小写。我在 discord.js 版本 12.2.0 上,这是我的代码:

client.on("message", (message) => {
    if (message.author.bot) return;
    msg = message.content.toLowerCase();
    if (message.startsWith(prefix + "laugh")) {
      message.author.send ("```haha lmao```")
    }
}

我一直在互联网上搜索我的问题,但没有一个能解决我的问题。自从我收到此错误以来已经 3 天了。

标签: javascriptdiscord.js

解决方案


可能startsWith不支持。检查是否String.prototype.startsWith为真。

你也可以indexOf改用。

if (message.indexOf(prefix + "laugh") === 0) {
    message.author.send ("```haha lmao```")
}

推荐阅读