如何使discord.js 11不区分大小写? [英] How to make discord.js 11 not case sensitive?

查看:25
本文介绍了如何使discord.js 11不区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Discord js 11进行的反咒骂,它使用了一个名为bannedwords.txt的文件.有没有一种方法可以使我在不区分大小写的情况下读取文件.例如,如果其中一个禁忌词是鸡肉",我想这样做,就禁止了鸡",鸡",鸡",鸡",鸡".我该怎么做?

I have an anti swear made in discord js 11 and it uses a file called bannedwords.txt. Is there a way I can make it read the file without being case sensitive. For instance if one of the banned words was chicken, I wanna make it so it bans CHICKen, CHicken, Chicken, chicken, ChiCKeN, you get the point. How do I do this?

推荐答案

您可以使用字符串的 toLowerCase()方法来实现此目的.只需在要检查的脏话消息和/或要检查的违禁单词上调用它即可.这是一个示例:

You can use the toLowerCase() method of strings to achieve this. Simply call it on both the message being checked for swearing, and/or on the banned word it is being checked for. Here's an example:

checkProfanity: function(message, bannedWords) {
    var words = message.split(' ');
    for (var word of words) {
      if (bannedWords.indexOf(word.toLowerCase()) > -1) return true;
    }
    return false;
}

这是您的 punishment.js 文件,以使过滤器不区分大小写.由于 bannedwords.txt 文件中的所有禁止词都是小写的,因此我们可以简单地将消息中的每个单词都转换为小写,以使该词与禁止词之间的比较成为可能.

This is the modification necessary in your punishment.js file to make your filter case insensitive. Since all of the banned words in your bannedwords.txt file are lowercase, we can simply convert each individual word of the message to lowercase to make the comparison between the word and banned word possible.

这篇关于如何使discord.js 11不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆