diff --git a/src/events/channelUpdate.ts b/src/events/channelUpdate.ts
index 568af0b..89692e8 100644
--- a/src/events/channelUpdate.ts
+++ b/src/events/channelUpdate.ts
@@ -1,135 +1,133 @@
-import humanizeDuration from 'humanize-duration';
-import getEmojiByName from '../utils/getEmojiByName.js';
+import humanizeDuration from "humanize-duration";
+import getEmojiByName from "../utils/getEmojiByName.js";
 
-export const event = 'channelUpdate';
+export const event = "channelUpdate";
 
 export async function callback(client, oc, nc) {
-    try {
-        let config = await client.memory.readGuildInfo(nc.guild.id);
-        const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderChannel } = client.logger
+    const config = await client.memory.readGuildInfo(nc.guild.id);
+    const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderChannel } = client.logger;
 
-        if (nc.parent && (nc.parent.id === config.tickets.category)) return
+    if (nc.parent && (nc.parent.id === config.tickets.category)) return;
 
-        let auditLog = await getAuditLog(nc.guild, 'CHANNEL_UPDATE');
-        let audit = auditLog.entries.filter(entry => entry.target.id === nc.id).first();
-        if (audit.executor.id === client.user.id) return;
+    const auditLog = await getAuditLog(nc.guild, "CHANNEL_UPDATE");
+    const audit = auditLog.entries.filter(entry => entry.target.id === nc.id).first();
+    if (audit.executor.id === client.user.id) return;
 
-        let emoji:string;
-        let readableType:string;
-        let displayName:string ;
-        let changes = {
-            channelId: entry(nc.id, `\`${nc.id}\``),
-            channel: entry(nc.id, renderChannel(nc)),
-            edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
-            editedBy: entry(audit.executor.id, renderUser((await nc.guild.members.fetch(audit.executor.id)).user)),
+    let emoji:string;
+    let readableType:string;
+    let displayName:string ;
+    const changes = {
+        channelId: entry(nc.id, `\`${nc.id}\``),
+        channel: entry(nc.id, renderChannel(nc)),
+        edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+        editedBy: entry(audit.executor.id, renderUser((await nc.guild.members.fetch(audit.executor.id)).user))
+    };
+    if (oc.name !== nc.name) changes["name"] = entry([oc.name, nc.name], `${oc.name} -> ${nc.name}`);
+    if (oc.position !== nc.position) changes["position"] = entry([oc.position, nc.position], `${oc.position} -> ${nc.position}`);
+
+    switch (nc.type) {
+    case "GUILD_TEXT": {
+        emoji = "CHANNEL.TEXT.EDIT";
+        readableType = "Text";
+        displayName = "Text Channel";
+        let oldTopic = oc.topic, newTopic = nc.topic;
+        if (oldTopic) {
+            if (oldTopic.length > 256) oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
+            else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
+        } else { oldTopic = "None"; }
+        if (newTopic) {
+            if (newTopic.length > 256) newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
+            else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
+        } else { newTopic = "None"; }
+        const nsfw = ["", ""];
+        nsfw[0] = oc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+        nsfw[1] = nc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+        if (oc.topic !== nc.topic) changes["description"] = entry([oc.topic, nc.topic], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
+        if (oc.nsfw !== nc.nsfw) changes["nsfw"] = entry([oc.nsfw, nc.nsfw], `${nsfw[0]} -> ${nsfw[1]}`);
+        if (oc.rateLimitPerUser !== nc.rateLimitPerUser) changes["rateLimitPerUser"] = entry(
+            [oc.rateLimitPerUser, nc.rateLimitPerUser],
+            `${humanizeDuration(oc.rateLimitPerUser * 1000)} -> ${humanizeDuration(nc.rateLimitPerUser * 1000)}`
+        );
+
+        break;
+    }
+    case "GUILD_NEWS": {
+        emoji = "CHANNEL.TEXT.EDIT";
+        readableType = "News";
+        displayName = "News Channel";
+        let oldTopic = oc.topic, newTopic = nc.topic;
+        if (oldTopic) {
+            if (oldTopic.length > 256) oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
+            else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
+        } else { oldTopic = "None"; }
+        if (newTopic) {
+            if (newTopic.length > 256) newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
+            else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
+        } else { newTopic = "None"; }
+        if (oc.nsfw !== nc.nsfw) changes["nsfw"] = entry([oc.nsfw, nc.nsfw], `${oc.nsfw ? "On" : "Off"} -> ${nc.nsfw ? "On" : "Off"}`);
+        break;
+    }
+    case "GUILD_VOICE": {
+        emoji = "CHANNEL.VOICE.EDIT";
+        readableType = "Voice";
+        displayName = "Voice Channel";
+        if (oc.bitrate !== nc.bitrate) changes["bitrate"] = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
+        if (oc.userLimit !== nc.userLimit) changes["maxUsers"] = entry([oc.userLimit, nc.userLimit], `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`);
+        if (oc.rtcRegion !== nc.rtcRegion) changes["region"] = entry(
+            [oc.rtcRegion, nc.rtcRegion],
+            `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
+        );
+        break;
+    }
+    case "GUILD_STAGE": {
+        emoji = "CHANNEL.VOICE.EDIT";
+        readableType = "Stage";
+        displayName = "Stage Channel";
+        let oldTopic = oc.topic, newTopic = nc.topic;
+        if (oldTopic) {
+            if (oldTopic.length > 256) oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
+            else oldTopic = `\`\`\`\n${oldTopic.replace("`", "'")}\n\`\`\``;
+        } else { oldTopic = "None"; }
+        if (newTopic) {
+            if (newTopic.length > 256) newTopic = `\`\`\`\n${newTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
+            else newTopic = `\`\`\`\n${newTopic.replace("`", "'")}\n\`\`\``;
+        } else { newTopic = "None"; }
+        if (oc.bitrate !== nc.bitrate) changes["bitrate"] = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
+        if (oc.userLimit !== nc.userLimit) changes["maxUsers"] = entry([oc.userLimit, nc.userLimit], `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`);
+        if (oc.rtcRegion !== nc.rtcRegion) changes["region"] = entry(
+            [oc.rtcRegion, nc.rtcRegion],
+            `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
+        );
+        break;
+    }
+    case "GUILD_CATEGORY": {
+        emoji = "CHANNEL.CATEGORY.EDIT";
+        readableType = "Category";
+        displayName = "Category";
+        break;
+    }
+    default: {
+        emoji = "CHANNEL.TEXT.EDIT";
+        readableType = "Channel";
+        displayName = "Channel";
+    }
+    }
+    const t = oc.type.split("_")[1];
+    if (oc.type !== nc.type) changes["type"] = entry([oc.type, nc.type], `${t[0] + t.splice(1).toLowerCase()} -> ${readableType}`);
+    if (!(Object.values(changes).length - 4)) return;
+    const data = {
+        meta:{
+            type: "channelUpdate",
+            displayName: displayName + " Edited",
+            calculateType: "channelUpdate",
+            color: NucleusColors.yellow,
+            emoji: emoji,
+            timestamp: audit.createdTimestamp
+        },
+        list: changes,
+        hidden: {
+            guild: nc.guild.id
         }
-        if (oc.name !== nc.name) changes["name"] = entry([oc.name, nc.name], `${oc.name} -> ${nc.name}`);
-        if (oc.position !== nc.position) changes["position"] = entry([oc.position, nc.position], `${oc.position} -> ${nc.position}`);
-
-        switch (nc.type) {
-            case 'GUILD_TEXT': {
-                emoji = "CHANNEL.TEXT.EDIT";
-                readableType = "Text";
-                displayName = "Text Channel"
-                let oldTopic = oc.topic, newTopic = nc.topic;
-                if (oldTopic) {
-                    if (oldTopic.length > 256) oldTopic = `\`\`\`\n${oldTopic.replace('`', "'").substring(0, 253) + '...'}\n\`\`\``
-                    else oldTopic = `\`\`\`\n${oldTopic.replace('`', "'")}\n\`\`\``
-                } else { oldTopic = "None"; }
-                if (newTopic) {
-                    if (newTopic.length > 256) newTopic = `\`\`\`\n${newTopic.replace('`', "'").substring(0, 253) + '...'}\n\`\`\``
-                    else newTopic = `\`\`\`\n${newTopic.replace('`', "'")}\n\`\`\``
-                } else { newTopic = "None"; }
-                let nsfw = ["", ""]
-                nsfw[0] = oc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
-                nsfw[1] = nc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
-                if (oc.topic !== nc.topic) changes["description"] = entry([oc.topic, nc.topic], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
-                if (oc.nsfw !== nc.nsfw) changes["nsfw"] = entry([oc.nsfw, nc.nsfw], `${nsfw[0]} -> ${nsfw[1]}`);
-                if (oc.rateLimitPerUser !== nc.rateLimitPerUser) changes["rateLimitPerUser"] = entry(
-                    [oc.rateLimitPerUser, nc.rateLimitPerUser],
-                    `${humanizeDuration(oc.rateLimitPerUser * 1000)} -> ${humanizeDuration(nc.rateLimitPerUser * 1000)}`
-                );
-
-                break;
-            }
-            case 'GUILD_NEWS': {
-                emoji = "CHANNEL.TEXT.EDIT";
-                readableType = "News";
-                displayName = "News Channel"
-                let oldTopic = oc.topic, newTopic = nc.topic;
-                if (oldTopic) {
-                    if (oldTopic.length > 256) oldTopic = `\`\`\`\n${oldTopic.replace('`', "'").substring(0, 253) + '...'}\n\`\`\``
-                    else oldTopic = `\`\`\`\n${oldTopic.replace('`', "'")}\n\`\`\``
-                } else { oldTopic = "None"; }
-                if (newTopic) {
-                    if (newTopic.length > 256) newTopic = `\`\`\`\n${newTopic.replace('`', "'").substring(0, 253) + '...'}\n\`\`\``
-                    else newTopic = `\`\`\`\n${newTopic.replace('`', "'")}\n\`\`\``
-                } else { newTopic = "None"; }
-                if (oc.nsfw !== nc.nsfw) changes["nsfw"] = entry([oc.nsfw, nc.nsfw], `${oc.nsfw ? "On" : "Off"} -> ${nc.nsfw ? "On" : "Off"}`);
-                break;
-            }
-            case 'GUILD_VOICE': {
-                emoji = "CHANNEL.VOICE.EDIT";
-                readableType = "Voice";
-                displayName = "Voice Channel"
-                if (oc.bitrate !== nc.bitrate) changes["bitrate"] = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
-                if (oc.userLimit !== nc.userLimit) changes["maxUsers"] = entry([oc.userLimit, nc.userLimit], `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`);
-                if (oc.rtcRegion !== nc.rtcRegion) changes["region"] = entry(
-                    [oc.rtcRegion, nc.rtcRegion],
-                    `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
-                );
-                break;
-            }
-            case 'GUILD_STAGE': {
-                emoji = "CHANNEL.VOICE.EDIT";
-                readableType = "Stage";
-                displayName = "Stage Channel"
-                let oldTopic = oc.topic, newTopic = nc.topic;
-                if (oldTopic) {
-                    if (oldTopic.length > 256) oldTopic = `\`\`\`\n${oldTopic.replace('`', "'").substring(0, 253) + '...'}\n\`\`\``
-                    else oldTopic = `\`\`\`\n${oldTopic.replace('`', "'")}\n\`\`\``
-                } else { oldTopic = "None"; }
-                if (newTopic) {
-                    if (newTopic.length > 256) newTopic = `\`\`\`\n${newTopic.replace('`', "'").substring(0, 253) + '...'}\n\`\`\``
-                    else newTopic = `\`\`\`\n${newTopic.replace('`', "'")}\n\`\`\``
-                } else { newTopic = "None"; }
-                if (oc.bitrate !== nc.bitrate) changes["bitrate"] = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
-                if (oc.userLimit !== nc.userLimit) changes["maxUsers"] = entry([oc.userLimit, nc.userLimit], `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`);
-                if (oc.rtcRegion !== nc.rtcRegion) changes["region"] = entry(
-                    [oc.rtcRegion, nc.rtcRegion],
-                    `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
-                );
-                break;
-            }
-            case 'GUILD_CATEGORY': {
-                emoji = "CHANNEL.CATEGORY.EDIT";
-                readableType = "Category";
-                displayName = "Category"
-                break;
-            }
-            default: {
-                emoji = "CHANNEL.TEXT.EDIT";
-                readableType = "Channel";
-                displayName = "Channel"
-            }
-        }
-        let t = oc.type.split("_")[1];
-        if (oc.type !== nc.type) changes["type"] = entry([oc.type, nc.type], `${t[0] + t.splice(1).toLowerCase()} -> ${readableType}`);
-        if (!(Object.values(changes).length - 4)) return
-        let data = {
-            meta:{
-                type: 'channelUpdate',
-                displayName: displayName + ' Edited',
-                calculateType: 'channelUpdate',
-                color: NucleusColors.yellow,
-                emoji: emoji,
-                timestamp: audit.createdTimestamp
-            },
-            list: changes,
-            hidden: {
-                guild: nc.guild.id
-            }
-        }
-        log(data);
-    } catch {}
+    };
+    log(data);
 }
\ No newline at end of file
