diff --git a/src/events/guildUpdate.ts b/src/events/guildUpdate.ts
new file mode 100644
index 0000000..400cfe4
--- /dev/null
+++ b/src/events/guildUpdate.ts
@@ -0,0 +1,58 @@
+export const event = 'guildUpdate'
+
+export async function callback(client, before, after) {
+    try {
+        const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = after.client.logger
+        let auditLog = await getAuditLog(after, 'GUILD_UPDATE');
+        let audit = auditLog.entries.filter(entry => entry.target.id == after.id).first();
+        if (audit.executor.id == client.user.id) return;
+        let list = {}
+
+        const verificationLevels = {
+            NONE: 'Unrestricted',
+            LOW: 'Verified email',
+            MEDIUM: 'Registered (5 minutes)',
+            HIGH: 'Member (10 minutes)',
+            VERY_HIGH: 'Verified phone'
+        }
+
+        const explicitContentFilterLevels = {
+            DISABLED: 'Disabled',
+            MEMBERS_WITHOUT_ROLES: 'Members without roles',
+            ALL_MEMBERS: 'All members'
+        }
+
+        const MFALevels = {
+            NONE: 'None',
+            ELEVATED: 'Enabled'
+        }
+
+        if (before.name != after.name) list["name"] = entry([before.name, after.name], `${before.name} -> ${after.name}`);
+        if (before.icon != after.icon) list["icon"] = entry([before.icon, after.icon], `[Before](${before.iconURL()}) -> [After](${after.iconURL()})`);
+        if (before.splash != after.splash) list["splash"] = entry([before.splash, after.splash], `[Before](${before.splashURL()}) -> [After](${after.splashURL()})`);
+        if (before.banner != after.banner) list["banner"] = entry([before.banner, after.banner], `[Before](${before.bannerURL()}) -> [After](${after.bannerURL()})`);
+        if (before.owner != after.owner) list["owner"] = entry([before.owner, after.owner], `${renderUser(before.owner.user)} -> ${renderUser(after.owner.user)}`);
+        if (before.verificationLevel != after.verificationLevel) list["verificationLevel"] = entry([verificationLevels[before.verificationLevel], verificationLevels[after.verificationLevel]], `${verificationLevels[before.verificationLevel]} -> ${verificationLevels[after.verificationLevel]}`);
+        if (before.explicitContentFilter != after.explicitContentFilter) list["explicitContentFilter"] = entry([explicitContentFilterLevels[before.explicitContentFilter], explicitContentFilterLevels[after.explicitContentFilter]], `${explicitContentFilterLevels[before.explicitContentFilter]} -> ${explicitContentFilterLevels[after.explicitContentFilter]}`);
+        if (before.mfaLevel != after.mfaLevel) list["2 factor authentication"] = entry([MFALevels[before.mfaLevel], MFALevels[after.mfaLevel]], `${MFALevels[before.mfaLevel]} -> ${MFALevels[after.mfaLevel]}`);
+
+        if (!(Object.keys(list).length)) return;
+        list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime()))
+        list["updatedBy"] = entry(audit.executor.id, renderUser(audit.executor))
+        let data = {
+            meta: {
+                type: 'guildUpdate',
+                displayName: 'Guild Edited',
+                calculateType: 'guildUpdate',
+                color: NucleusColors.yellow,
+                emoji: "GUILD.YELLOW",
+                timestamp: new Date().getTime()
+            },
+            list: list,
+            hidden: {
+                guild: after.id
+            }
+        }
+        log(data, after.client);
+    } catch (e) {}
+}
