diff --git a/src/events/threadUpdate.ts b/src/events/threadUpdate.ts
index 9125fcb..bcf73fa 100644
--- a/src/events/threadUpdate.ts
+++ b/src/events/threadUpdate.ts
@@ -1,44 +1,44 @@
-import type { GuildAuditLogsEntry, ThreadChannel } from "discord.js";
+import { AuditLogEvent, GuildAuditLogsEntry, ThreadChannel } from "discord.js";
 // @ts-expect-error
 import humanizeDuration from "humanize-duration";
 import type { NucleusClient } from "../utils/client.js";
 
 export const event = "threadUpdate";
 
-export async function callback(client: NucleusClient, before: ThreadChannel, after: ThreadChannel) {
+export async function callback(client: NucleusClient, oldThread: ThreadChannel, newThread: ThreadChannel) {
     const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
-    const auditLog = await getAuditLog(after.guild, "THREAD_UPDATE");
-    const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === after.id).first();
-    if (audit.executor.id === client.user.id) return;
+    const auditLog = (await getAuditLog(newThread.guild, AuditLogEvent.ThreadUpdate))
+        .filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === newThread.id)[0] as GuildAuditLogsEntry;
+    if (auditLog.executor!.id === client.user!.id) return;
     const list: Record<string, ReturnType<typeof entry>> = {
-        threadId: entry(after.id, `\`${after.id}\``),
-        thread: entry(after.name, renderChannel(after)),
-        parentChannel: entry(after.parentId, renderChannel(after.parent))
+        threadId: entry(newThread.id, `\`${newThread.id}\``),
+        thread: entry(newThread.name, renderChannel(newThread)),
+        parentChannel: entry(newThread.parentId, renderChannel(newThread.parent!))
     };
-    if (before.name !== after.name) {
-        list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`);
+    if (oldThread.name !== newThread.name) {
+        list["name"] = entry([oldThread.name, newThread.name], `${oldThread.name} -> ${newThread.name}`);
     }
-    if (before.autoArchiveDuration !== after.autoArchiveDuration) {
+    if (oldThread.autoArchiveDuration !== newThread.autoArchiveDuration) {
         list["autoArchiveDuration"] = entry(
-            [before.autoArchiveDuration, after.autoArchiveDuration],
-            `${humanizeDuration((before.autoArchiveDuration ?? 0) * 60 * 1000, {
+            [oldThread.autoArchiveDuration!.toString(), newThread.autoArchiveDuration!.toString()],
+            `${humanizeDuration((oldThread.autoArchiveDuration ?? 0) * 60 * 1000, {
                 round: true
-            })} -> ${humanizeDuration((after.autoArchiveDuration ?? 0) * 60 * 1000, {
+            })} -> ${humanizeDuration((newThread.autoArchiveDuration ?? 0) * 60 * 1000, {
                 round: true
             })}`
         );
     }
-    if (before.rateLimitPerUser !== after.rateLimitPerUser) {
+    if (oldThread.rateLimitPerUser !== newThread.rateLimitPerUser) {
         list["slowmode"] = entry(
-            [before.rateLimitPerUser, after.rateLimitPerUser],
-            `${humanizeDuration((before.rateLimitPerUser ?? 0) * 1000)} -> ${humanizeDuration(
-                (after.rateLimitPerUser ?? 0) * 1000
+            [oldThread.rateLimitPerUser!.toString(), newThread.rateLimitPerUser!.toString()],
+            `${humanizeDuration((oldThread.rateLimitPerUser ?? 0) * 1000)} -> ${humanizeDuration(
+                (newThread.rateLimitPerUser ?? 0) * 1000
             )}`
         );
     }
     if (!(Object.keys(list).length - 3)) return;
     list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime()));
-    list["updatedBy"] = entry(audit.executor.id, renderUser(audit.executor));
+    list["updatedBy"] = entry(auditLog.executor!.id, renderUser(auditLog.executor!));
     const data = {
         meta: {
             type: "channelUpdate",
@@ -50,7 +50,7 @@
         },
         list: list,
         hidden: {
-            guild: after.guild.id
+            guild: newThread.guild.id
         }
     };
     log(data);
