From 5ddc2dec0b6797a2ba3f755c9f973b56fa9b0b25 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Fri, 2 Feb 2024 07:12:15 +1100 Subject: [PATCH] Attempt to prevent `undefined: null` in purge log --- src/events/messageDeleteBulk.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/events/messageDeleteBulk.ts b/src/events/messageDeleteBulk.ts index 02ca3d0..3ea8858 100644 --- a/src/events/messageDeleteBulk.ts +++ b/src/events/messageDeleteBulk.ts @@ -3,6 +3,16 @@ import TClient from '../client.js'; export default class MessageDeleteBulk { static run(client:TClient, messages:Discord.Collection>, channel:Discord.GuildTextBasedChannel){ if (!client.config.botSwitches.logs || channel.guildId != client.config.dcServer.id) return; - (client.channels.resolve(client.config.dcServer.channels.logs) as Discord.TextChannel).send({embeds: [new client.embed().setColor(client.config.embedColorRed).setTimestamp().setTitle(`${messages.size} messages were purged`).setDescription(`\`\`\`${messages.map(msgs=>`${msgs.author?.username}: ${msgs.content}`).reverse().join('\n').slice(0,3900)}\`\`\``).addFields({name: 'Channel', value: `<#${messages.first().channel.id}>`})]}) + if (messages.some(msg=>{ + msg.author?.username === undefined ?? null; + msg.content === undefined ?? null; + })) return; + + (client.channels.resolve(client.config.dcServer.channels.logs) as Discord.TextChannel).send({embeds: [ + new client.embed().setColor(client.config.embedColorRed).setTimestamp() + .setTitle(`${messages.size} messages were purged`) + .setDescription(`\`\`\`${messages.map(msgs=>`${msgs.author?.username}: ${msgs.content}`).reverse().join('\n').slice(0,3900)}\`\`\``) + .addFields({name: 'Channel', value: `<#${messages.first().channel.id}>`}) + ]}); } }