diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts
index 412ac96..b674060 100644
--- a/src/events/guildMemberUpdate.ts
+++ b/src/events/guildMemberUpdate.ts
@@ -1,60 +1,76 @@
 import { AuditLogEvent, GuildAuditLogsEntry, GuildMember } from "discord.js";
 import type { NucleusClient } from "../utils/client.js";
 import type { LoggerOptions } from "../utils/log.js";
+import { generalException } from "../utils/createTemporaryStorage.js";
 
 export const event = "guildMemberUpdate";
 
 export async function callback(client: NucleusClient, before: GuildMember, after: GuildMember) {
     const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
 
+    if(!before.roles.cache.equals(after.roles.cache)) {
+        const auditLog = (await getAuditLog(after.guild, AuditLogEvent.MemberRoleUpdate))
+            .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === after.id)[0];
+        if (!auditLog) return;
+        if (client.noLog.includes(`${after.guild.id}${after.id}${auditLog.id}`)) return;
+        generalException(`${after.guild.id}${after.id}${auditLog.id}`);
+        if (auditLog.executor!.id !== client.user!.id) {
+            const rolesAdded = after.roles.cache.filter(role => !before.roles.cache.has(role.id));
+            const rolesRemoved = before.roles.cache.filter(role => !after.roles.cache.has(role.id));
+            let displayName = "Roles Removed";
+            let color = NucleusColors.red;
+            let emoji = "GUILD.ROLES.DELETE";
+            if(rolesAdded.size > 0 && rolesRemoved.size > 0) {displayName = "Roles Changed"; color = NucleusColors.yellow; emoji = "GUILD.ROLES.EDIT";}
+            else if(rolesAdded.size > 0) {displayName = "Roles Added"; color = NucleusColors.green; emoji = "GUILD.ROLES.CREATE";}
+            const removedEntry = rolesRemoved.map(role => role.id);
+            const addedEntry = rolesAdded.map(role => role.id);
+
+            let list = {
+                memberId: entry(after.id, `\`${after.id}\``),
+                name: entry(after.user.id, renderUser(after.user)),
+            };
+
+            if (rolesAdded.size > 0) {
+                list = Object.assign(list, {rolesAdded: entry(addedEntry, addedEntry.map(id => `<@&${id}>`).join(", "))});
+            }
+            if (rolesRemoved.size > 0) {
+                list = Object.assign(list, {rolesRemoved: entry(removedEntry, removedEntry.map(id => `<@&${id}>`).join(", "))});
+            }
+
+            list = Object.assign(list, {
+                changed: entry(Date.now(), renderDelta(Date.now())),
+                changedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!))
+            });
+
+            let data: LoggerOptions = {
+                meta: {
+                    type: "memberUpdate",
+                    displayName: displayName,
+                    calculateType: "guildMemberUpdate",
+                    color: color,
+                    emoji: emoji,
+                    timestamp: Date.now()
+                },
+                list: {},
+                hidden: {
+                    guild: after.guild.id
+                }
+            };
+
+            if(rolesAdded.size > 0) {
+                list = Object.assign(list, {rolesAdded: entry(addedEntry, addedEntry.map(id => `<@&${id}>`).join(", "))});
+            }
+            if(rolesRemoved.size > 0) {
+                list = Object.assign(list, {rolesRemoved: entry(removedEntry, removedEntry.map(id => `<@&${id}>`).join(", "))});
+            }
+            data = Object.assign(data, {list: list});
+            log(data);
+        }
+    }
     const auditLog = (await getAuditLog(after.guild, AuditLogEvent.MemberUpdate))
         .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === after.id)[0];
     if (!auditLog) return;
     if (auditLog.executor!.id === client.user!.id) return;
-    if(!before.roles.cache.equals(after.roles.cache)) {
-        let rolesAdded = after.roles.cache.filter(role => !before.roles.cache.has(role.id));
-        let rolesRemoved = before.roles.cache.filter(role => !after.roles.cache.has(role.id));
-        let displayName = "Roles Removed";
-        let color = NucleusColors.red;
-        let emoji = "GUILD.ROLES.DELETE";
-        if(rolesAdded.size > 0 && rolesRemoved.size > 0) {displayName = "Roles Changed"; color = NucleusColors.yellow; emoji = "GUILD.ROLES.EDIT";}
-        else if(rolesAdded.size > 0) {displayName = "Roles Added"; color = NucleusColors.green; emoji = "GUILD.ROLES.CREATE";}
-        let removedEntry = rolesRemoved.map(role => role.id);
-        let addedEntry = rolesAdded.map(role => role.id);
-
-        let list = {
-            memberId: entry(after.id, `\`${after.id}\``),
-            name: entry(after.user.id, renderUser(after.user)),
-            changed: entry(Date.now(), renderDelta(Date.now())),
-            changedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!))
-        };
-
-        let data: LoggerOptions = {
-            meta: {
-                type: "memberUpdate",
-                displayName: displayName,
-                calculateType: "guildMemberUpdate",
-                color: color,
-                emoji: emoji,
-                timestamp: Date.now()
-            },
-            list: {
-
-            },
-            hidden: {
-                guild: after.guild.id
-            }
-        };
-
-        if(rolesAdded.size > 0) {
-            list = Object.assign(list, {rolesAdded: entry(addedEntry, addedEntry.map(id => `<@&${id}>`).join(", "))});
-        }
-        if(rolesRemoved.size > 0) {
-            list = Object.assign(list, {rolesRemoved: entry(removedEntry, removedEntry.map(id => `<@&${id}>`).join(", "))});
-        }
-        data = Object.assign(data, {list: list});
-        log(data);
-    }
     if (before.nickname !== after.nickname) {
         await client.database.history.create(
             "nickname",
