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

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

问题描述

我有一个用 discord js 11 制作的反发誓,它使用了一个名为 bananwords.txt 的文件.有没有办法让它读取文件而不区分大小写.例如,如果其中一个被禁止的词是鸡肉,我想让它禁止 CHICKen、CHicken、Chicken、Chicken、ChiCKeN,你明白了.我该怎么做?

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天全站免登陆