'I'm Trying to make a word blacklist for discord.js using an sql database

I'm currently attempting to create a word blacklist command, I can currently write to the database however I'm having issues pulling the word into an array

module.exports = {
  name: 'blacklistword',
  description: "Blacklists a word for that server",
  async execute(client, message, cmd, args, Discord){

if(message.author.id !== '513413045251342336') return;

  if(!message.member.permissions.has('ADMINISTRATOR')) return message.channel.send(`Not Enough Permissions to Execute Command`)
  let text = `{'${args[0]}'}`
  let blacklistedWord = await getBlacklist(message, client, args, text)



    if(text){
      if(args[1] === 'remove' || args[1] === 'Remove'){
        if(blacklistedWord){
        client.db.query(`delete from blacklisted_words where guild_id = $1 and text = $2`, [message.guild.id, text])
        message.channel.send(`**${args[0]}** was removed from blacklisted words`)
      } else {
        message.channel.send(`**${args[0]}** is not A blacklisted word`)
      }
        return
      }

      try{
        await client.db.query(`insert into blacklisted_words (guild_id, text) values ($1, $2)`, [message.guild.id, text])
        message.channel.send(`**${args[0]}** was added to blacklisted words`)
      } catch (err) {
          message.channel.send(`**${args[0]}** is already a blacklisted words`)
      }

    } else {
      message.channel.send('Please add the word you would like to blacklist')
    }
  }
  }


  async function getBlacklist(message, client, args, text){
  const response = await client.db.query(`select text from blacklisted_words where guild_id = $1 and text = $2`, [message.guild.id, text])
  if(response && response.rowCount) return response.rows[0].text
  return null;
  }

this is for adding the blacklisted word guild_id is set to Character Varying and text is set to character varying[]

in my messageCreate.js file I have

 let blacklisted = getBlacklistWord(message, client)


     let foundInText = false;
     for (var i in blacklisted) {
       if (message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
     }
     if (foundInText) {
     if(message.author.bot) {
         return;
        }
       message.delete();
       message.channel.send(`**${message.author.username}** Please Refrain from using blacklisted words`);
     }

async function getBlacklistWord(message, client){
  const response = await client.db.query(`select text from blacklisted_words where guild_id = $1`, [message.guild.id])
  if(response && response.rowCount) return response.rows[0].text
  return null;
}

I have the blacklistword command working to add words to the database I'm just having issues with messageCreate grabbing those words to delete them and such, If anyone can help I'll be forever grateful thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source