diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts
index f8433fc..9563a33 100644
--- a/src/events/messageDelete.ts
+++ b/src/events/messageDelete.ts
@@ -4,61 +4,58 @@
 export const event = "messageDelete";
 
 export async function callback(client: NucleusClient, message: Message) {
-    try {
-        if (message.author.id === client.user!.id) return;
-        if (client.noLog.includes(`${message.id}/${message.channel.id}/${message.id}`)) return;
-        const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
-        const auditLog = (await getAuditLog(message.guild!, AuditLogEvent.MemberBanAdd))
-            .filter((entry: GuildAuditLogsEntry) => (entry.target! as User).id === message.author.id)[0];
-        if (auditLog) {
-            if (auditLog.createdTimestamp - 1000 < new Date().getTime()) return;
-        }
-        const replyTo = message.reference;
-        let content = message.cleanContent;
-        content.replace("`", "\\`");
-        if (content.length > 256) content = content.substring(0, 253) + "...";
-        const attachments =
-            message.attachments.size + (
-                message.content.match(
-                    /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
-                ) ?? []
-            ).length;
-        let attachmentJump = "";
-        const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
-            message.channel.id + message.id
-        ];
-        if (config) { attachmentJump = ` [[View attachments]](${config})`; }
-        const data = {
-            meta: {
-                type: "messageDelete",
-                displayName: "Message Deleted",
-                calculateType: "messageDelete",
-                color: NucleusColors.red,
-                emoji: "MESSAGE.DELETE",
-                timestamp: new Date().getTime()
-            },
-            separate: {
-                start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
-            },
-            list: {
-                messageId: entry(message.id, `\`${message.id}\``),
-                sentBy: entry(message.author.id, renderUser(message.author)),
-                sentIn: entry(message.channel.id, renderChannel(message.channel as Discord.GuildChannel | Discord.ThreadChannel)),
-                deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
-                mentions: message.mentions.users.size,
-                attachments: entry(attachments, attachments + attachmentJump),
-                repliedTo: entry(
-                    replyTo ? replyTo.messageId! : null,
-                    replyTo ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
-                            : "None"
-                )
-            },
-            hidden: {
-                guild: message.guild!.id
-            }
-        };
-        log(data);
-    } catch (e) {
-        console.log(e);
+    if (message.author.id === client.user!.id) return;
+    if (message.author.bot) return;
+    if (client.noLog.includes(`${message.id}/${message.channel.id}/${message.id}`)) return;
+    const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+    const auditLog = (await getAuditLog(message.guild!, AuditLogEvent.MemberBanAdd))
+        .filter((entry: GuildAuditLogsEntry) => (entry.target! as User).id === message.author.id)[0];
+    if (auditLog) {
+        if (auditLog.createdTimestamp - 1000 < new Date().getTime()) return;
     }
+    const replyTo = message.reference;
+    let content = message.cleanContent;
+    content.replace("`", "\\`");
+    if (content.length > 256) content = content.substring(0, 253) + "...";
+    const attachments =
+        message.attachments.size + (
+            message.content.match(
+                /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
+            ) ?? []
+        ).length;
+    let attachmentJump = "";
+    const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
+        message.channel.id + message.id
+    ];
+    if (config) { attachmentJump = ` [[View attachments]](${config})`; }
+    const data = {
+        meta: {
+            type: "messageDelete",
+            displayName: "Message Deleted",
+            calculateType: "messageDelete",
+            color: NucleusColors.red,
+            emoji: "MESSAGE.DELETE",
+            timestamp: new Date().getTime()
+        },
+        separate: {
+            start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
+        },
+        list: {
+            messageId: entry(message.id, `\`${message.id}\``),
+            sentBy: entry(message.author.id, renderUser(message.author)),
+            sentIn: entry(message.channel.id, renderChannel(message.channel as Discord.GuildChannel | Discord.ThreadChannel)),
+            deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+            mentions: message.mentions.users.size,
+            attachments: entry(attachments, attachments + attachmentJump),
+            repliedTo: entry(
+                replyTo ? replyTo.messageId! : null,
+                replyTo ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
+                        : "None"
+            )
+        },
+        hidden: {
+            guild: message.guild!.id
+        }
+    };
+    log(data);
 }
