javascript - 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 天了。
解决方案
可能startsWith
不支持。检查是否String.prototype.startsWith
为真。
你也可以indexOf
改用。
if (message.indexOf(prefix + "laugh") === 0) {
message.author.send ("```haha lmao```")
}
推荐阅读
- sql - 在 Oracle SQl 中拆分数据字段字符串值
- angular - 如何设置在Angular中构建期间打包文件的顺序
- r - 使用 R 在元分析中结合森林图和红绿灯图
- react-native - React-Native App 在 expo 上完美运行,但在发布后它显示出看不见的行为
- python - Python 日志记录失败,网络驱动器上的日志文件(Windows 10)
- php - Keycloak-传递参数以满足密码策略要求
- c++ - 使用协作组网格同步()函数时,CUDA 内核停止工作
- php - Hello World PHP 脚本的奇怪 php 输出
- sas - 处理面板数据时删除缺失值
- laravel - 我不能在 laravel 的数据面板上使用 onlyTrashed 方法