javascript - Discord.js - 如果消息包含,不区分大小写
问题描述
我想用我的 Discord Bot 阻止脏话。因此,我创建了一个我想要阻止的 JSON 文件并将其命名为swear_words
. 作为测试,我添加了 sware 进行测试。bot.js
然后我将它包含在我的文件顶部:
const { swear_words, mute_content } = require(`./swear-words.json`);
然后是我的阻塞代码,在底部:
client.on(`message`, message => {
for (var i=0; i < swear_words.length; i++) {
if (message.content.includes(swear_words[i])) {
message.delete();
message.channel.send(mute_content);
console.log("Someone tried to swear.");
}
}
});
这在我键入时有效sware
,但不是Sware
。所以我补充swear_words.prototype.toLowerCase()
说:
if (message.content.includes(swear_words.prototype.toLowerCase() === swear_words[i])) {}
然后我得到:
TypeError: Cannot read property 'toLowerCase' of undefined
这是什么?它不能读取我的 JSON 吗?
提前感谢您的帮助。
解决方案
用于.toLowerCase( )
消息内容,因为它返回一个字符串。
if (message.content.toLowerCase( ).includes(swear_words[i])) {
推荐阅读
- java - 程序中的存款和取款方式问题
- angular - Angular 8 到 11 超出最大调用堆栈大小
- tags - 需要在数据集中查找缺失/未配对的 XML 标记
- javascript - TextArea Undefined-JQuery 的 ID
- ios - 视图控制器的情节提要参考问题
- python - Python (Pillow) - 图像中的渐变颜色文本
- cron - 我无法在 crontab 上运行 Rscript
- apache-spark - 无法在火花直线中看到由 scala 应用程序创建的表
- sublimetext3 - 如何在 Sublime 文本中运行 java 文件?
- python-3.x - 如何在 Django 模型字段中获取字符串并确保它是否唯一