How can I search through an entire message for a word, break down that word into an array, and check other arrays to see if it matches?

Okay so I created a bot for a friend of mine that sends a sponge emoji and I’m trying to make it more difficult for members to try and work around it. How the bot works is if a message contains the word "sponge" it sends a sponge emoji. I’m trying to make it so if someone uses a character that looks like a regular character in the word, it still detects it and it sends the emoji, which makes it more challenging and fun. So far, this is what I have made:

//SPONGE MODULE

};
let s = ['Ⓢ','ⓢ','⒮','S','s','Ṡ','ṡ','Ṣ','ṣ','Ṥ','ṥ','Ṧ','ṧ','Ṩ','ṩ','Ś','ś','Ŝ','ŝ','Ş','ş','Š','š','Ș','ș','ȿ','ꜱ'];
let p = ['Ⓟ','ⓟ','⒫','℗','P','pvṔ','ṕ','Ṗ','ṗ','Ƥ','ƥ','Ᵽ','ℙ','Ƿ','ꟼ','℘'];
let o = ['Ⓞ','ⓞ','⒪','O','o','Ö','ö','Ṏ','ṏ','Ṍ','ṍ','Ṑ','ṑ','Ṓ','ṓ','Ȫ','ȫ','Ȭ','ȭ','Ȯ','ȯ','Ȱ','ȱ','Ǫ','ǫ','Ǭ','ǭ','Ọ','ọ','Ỏ','ỏ','Ố','ố','Ồ','ồ','Ổ','ổ','Ỗ','ỗ','Ộ','ộ','Ớ','ớ','Ờ','ờ','Ở','ở','Ỡ','ỡ','Ợ','ợ','Ơ','ơ','Ō','ō','Ŏ','ŏ','Ő','ő','Ò','ò','Ó','ó','Ô','ô','Õ','õ','Ǒ','ǒ','Ȍ','ȍ','Ȏ','ȏ','Ø','ø','Ǿ','ǿ','Ꝋ','⍥','⍤'];
let n = ['Ⓝ','ⓝ','⒩','N','n','Ṅ','ṅ','Ṇ','ṇ','Ṉ','ṉ','Ṋ','ṋ','Ń','ń','Ņ','ņ','Ň','ň','Ǹ','ǹ','Ñ','ñ','Ƞ','ƞ','Ŋ','ŋ','Ɲ','ʼn','NJ','Nj','nj','ȵ','ℕ'];
let g = ['Ⓖ','ⓖ','⒢','G','g','Ɠ','Ḡ','ḡ','Ĝ','ĝ','Ğ','ğ','Ġ','ġ','Ǥ','ǥ','Ǧ','ǧ','Ǵ','ℊ','⅁','ǵ','Ģ','ģ'];
let e = ['Ⓔ','ⓔ','⒠','E','e','Ḕ','ḕ','Ḗ','ḗ','Ḙ','ḙ','Ḛ','ḛ','Ḝ','ḝ','Ẹ','ẹ','Ẻ','ẻ','Ế','ế','Ẽ','ẽ','Ề','ề','Ể','ể','Ễ','ễ','Ệ','ệ','Ē','ē','Ĕ','ĕ','Ė','ė','Ę','ę','Ě','ě','È','è','É','é','Ê','ê','Ë','ë','Ȅ','ȅ','Ȩ','ȩ','Ȇ','ȇ','Ǝ','ⱻ','Ɇ','ɇ','Ə','ǝ','ℰ','ⱸ','ℯ','℮','ℇ','Ɛ'];

    for (var i = 0; i < spongeVariances.length; i++) {
        if (message.author.bot) return;
        if (message.content.toLowerCase().includes(spongeVariances[i])) {
            message.channel.send('🧽');
                break;
          }
    }
});

I am trying to make it so it searched each array for that particular character, and if it finds it, it goes onto the next one, and so on.

For instance, if someone types: Here is a spoṄgḜ, it should be able to detect both of those special characters and still send the sponge emoji.

How can I approach this?

35 thoughts on “How can I search through an entire message for a word, break down that word into an array, and check other arrays to see if it matches?”

  1. Here is working example

    const word = 'spoṄgḜ'
    
    const matrix = [
      ['Ⓢ', 'ⓢ', '⒮', 'S', 's', 'Ṡ', 'ṡ', 'Ṣ', 'ṣ', 'Ṥ', 'ṥ', 'Ṧ', 'ṧ', 'Ṩ', 'ṩ', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ș', 'ș', 'ȿ', 'ꜱ'],
      ['Ⓟ', 'ⓟ', '⒫', '℗', 'P', 'pvṔ', 'ṕ', 'Ṗ', 'ṗ', 'Ƥ', 'ƥ', 'Ᵽ', 'ℙ', 'Ƿ', 'ꟼ', '℘'],
      ['Ⓞ', 'ⓞ', '⒪', 'O', 'o', 'Ö', 'ö', 'Ṏ', 'ṏ', 'Ṍ', 'ṍ', 'Ṑ', 'ṑ', 'Ṓ', 'ṓ', 'Ȫ', 'ȫ', 'Ȭ', 'ȭ', 'Ȯ', 'ȯ', 'Ȱ', 'ȱ', 'Ǫ', 'ǫ', 'Ǭ', 'ǭ', 'Ọ', 'ọ', 'Ỏ', 'ỏ', 'Ố', 'ố', 'Ồ', 'ồ', 'Ổ', 'ổ', 'Ỗ', 'ỗ', 'Ộ', 'ộ', 'Ớ', 'ớ', 'Ờ', 'ờ', 'Ở', 'ở', 'Ỡ', 'ỡ', 'Ợ', 'ợ', 'Ơ', 'ơ', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Ò', 'ò', 'Ó', 'ó', 'Ô', 'ô', 'Õ', 'õ', 'Ǒ', 'ǒ', 'Ȍ', 'ȍ', 'Ȏ', 'ȏ', 'Ø', 'ø', 'Ǿ', 'ǿ', 'Ꝋ', '⍥', '⍤'],
      ['Ⓝ', 'ⓝ', '⒩', 'N', 'n', 'Ṅ', 'ṅ', 'Ṇ', 'ṇ', 'Ṉ', 'ṉ', 'Ṋ', 'ṋ', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'Ǹ', 'ǹ', 'Ñ', 'ñ', 'Ƞ', 'ƞ', 'Ŋ', 'ŋ', 'Ɲ', 'ʼn', 'NJ', 'Nj', 'nj', 'ȵ', 'ℕ'],
      ['Ⓖ', 'ⓖ', '⒢', 'G', 'g', 'Ɠ', 'Ḡ', 'ḡ', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ǥ', 'ǥ', 'Ǧ', 'ǧ', 'Ǵ', 'ℊ', '⅁', 'ǵ', 'Ģ', 'ģ'],
      ['Ⓔ', 'ⓔ', '⒠', 'E', 'e', 'Ḕ', 'ḕ', 'Ḗ', 'ḗ', 'Ḙ', 'ḙ', 'Ḛ', 'ḛ', 'Ḝ', 'ḝ', 'Ẹ', 'ẹ', 'Ẻ', 'ẻ', 'Ế', 'ế', 'Ẽ', 'ẽ', 'Ề', 'ề', 'Ể', 'ể', 'Ễ', 'ễ', 'Ệ', 'ệ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'È', 'è', 'É', 'é', 'Ê', 'ê', 'Ë', 'ë', 'Ȅ', 'ȅ', 'Ȩ', 'ȩ', 'Ȇ', 'ȇ', 'Ǝ', 'ⱻ', 'Ɇ', 'ɇ', 'Ə', 'ǝ', 'ℰ', 'ⱸ', 'ℯ', '℮', 'ℇ', 'Ɛ']
    ]
    
    let isSponge = false
    
    for (let i = 0; i < word.length; i++) {
      if (matrix[i].includes(word[i].toLowerCase()) || matrix[i].includes(word[i].toUpperCase())) {
        isSponge = true
      } else {
        isSponge = false
      }
    }
    
    console.log(isSponge)
    Reply

Leave a Comment