Can I get a logging function to ignore certain server channel categories?

Viewed 57

OK, so I'm coding a Discord bot. It already has a logging function, however I want it to ignore a specific category. Is there any way to do this easily? The logging code:

const { Server_Updates } = require("../settings/configuration").LOGGING;
const { MessageEmbed } = require(`discord.js`)

module.exports = {
    execute: async(Client, oldMessEDIT, newMessEDIT) => {
        const logChannel = Client.channels.cache.get(Server_Updates)

        if (oldMessEDIT.author && oldMessEDIT.author.bot) return undefined
        if (oldMessEDIT.content.length > 1020) return
        if (newMessEDIT.content.length > 1020) return // 
        if (!oldMessEDIT.guild) return

        let logEmbed = new MessageEmbed()
            .setAuthor("A message was edited!")
            .setColor(Client.color)
            .setTimestamp()
            .setFooter(`${newMessEDIT.guild.name} |  `, newMessEDIT.guild.iconURL({ dynamic: true, format: 'png' }))
            .addField("Message Before Edit:", oldMessEDIT.content)
            .addField("Message After Edit:", newMessEDIT.content)
            .addField("User:", `${newMessEDIT.author}`)
            .addField("Channel Message Was Edited In:", oldMessEDIT.channel.toString())

        if (logChannel) logChannel.send(logEmbed)
    },
    name: "messageUpdate",
};

The Config file attached to it:

    LOGGING: {
        Report_Channel: '848548626804375562',
        Ban_Channel_Logs: '848548626804375562',
        Unban_Channel_Logs: '848548626804375562',
        Kick_Channel_Logs: '848548626804375562',
        Warn_Channel_Logs: '848548626804375562',
        Mute_Channel_Logs: '848548626804375562',
        Lock_Channel_Logs: '848548626804375562',
        Ticket_Channel_Logs: '848548626804375562',
        Moderation_Channel_Logs: '848548626804375562',
        Server_Updates: '848548626804375562',
        Voice_Updates: '848548626804375562',
        Bypass_Category: '848550022798639134'
    },

Thanks in advance

2 Answers

alternatively you can add all the channel ID's into an array and then blacklist it

const { Server_Updates } = require("../settings/configuration").LOGGING;
const { MessageEmbed } = require(`discord.js`)

module.exports = {
    execute: async(Client, oldMessEDIT, newMessEDIT) => {
        const blacklistedChannels = [id, id2]; // replace them with actual ids
        if (blacklistedChannels.includes(oldMessEdit.channel.id) || blacklistedChannels.includes(newMessEdit.channel.id)) return console.log('command was ran in a blacklisted channel');
        const logChannel = Client.channels.cache.get(Server_Updates)

        if (oldMessEDIT.author && oldMessEDIT.author.bot) return undefined
        if (oldMessEDIT.content.length > 1020) return
        if (newMessEDIT.content.length > 1020) return // 
        if (!oldMessEDIT.guild) return

        let logEmbed = new MessageEmbed()
            .setAuthor("A message was edited!")
            .setColor(Client.color)
            .setTimestamp()
            .setFooter(`${newMessEDIT.guild.name} |  `, newMessEDIT.guild.iconURL({ dynamic: true, format: 'png' }))
            .addField("Message Before Edit:", oldMessEDIT.content)
            .addField("Message After Edit:", newMessEDIT.content)
            .addField("User:", `${newMessEDIT.author}`)
            .addField("Channel Message Was Edited In:", oldMessEDIT.channel.toString())

        if (logChannel) logChannel.send(logEmbed)
    },
    name: "messageUpdate",
};

to use category blacklist (i read docs)

const { Server_Updates } = require("../settings/configuration").LOGGING;
const { MessageEmbed } = require(`discord.js`)

module.exports = {
    execute: async(Client, oldMessEDIT, newMessEDIT) => {
        if (oldMessEdit.parent.id == 'category ID here' || newMessEdit.parent.id == 'category ID here') return console.log('command was ran in a blacklisted category');
        const logChannel = Client.channels.cache.get(Server_Updates)

        if (oldMessEDIT.author && oldMessEDIT.author.bot) return undefined
        if (oldMessEDIT.content.length > 1020) return
        if (newMessEDIT.content.length > 1020) return // 
        if (!oldMessEDIT.guild) return

        let logEmbed = new MessageEmbed()
            .setAuthor("A message was edited!")
            .setColor(Client.color)
            .setTimestamp()
            .setFooter(`${newMessEDIT.guild.name} |  `, newMessEDIT.guild.iconURL({ dynamic: true, format: 'png' }))
            .addField("Message Before Edit:", oldMessEDIT.content)
            .addField("Message After Edit:", newMessEDIT.content)
            .addField("User:", `${newMessEDIT.author}`)
            .addField("Channel Message Was Edited In:", oldMessEDIT.channel.toString())

        if (logChannel) logChannel.send(logEmbed)
    },
    name: "messageUpdate",
};

I edited it to:

execute: async(Client, oldMessEDIT, newMessEDIT) => {
const blacklistedCategories = [848550022798639134];
if (blacklistedCategories.includes(oldMessEdit.channel.id) || blacklistedChannels.includes(newMessEdit.channel.id)) return console.log('command was ran in a blacklisted channel');
const logChannel = Client.channels.cache.get(Server_Updates)
Related