From d29c358ddacab25423b8c51bf537eddf60e16e33 Mon Sep 17 00:00:00 2001 From: Stephen Michel Date: Wed, 24 Mar 2021 12:23:01 -0400 Subject: [PATCH] Fix: Don't crash if a message has no author When setting the status message, the bot looks for the prior message, to update it if it is found. To do this, it filters the message list by author id. However, sometimes a message does not have an author (unsure when; maybe when the author has left the server?), and the bot crashes. This slipped by for a long time because the types don't mark the author as nullable (although the api reference does). --- src/modules/helpchan.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/helpchan.ts b/src/modules/helpchan.ts index 5cfca5e7..db36549b 100644 --- a/src/modules/helpchan.ts +++ b/src/modules/helpchan.ts @@ -356,7 +356,7 @@ export class HelpChanModule extends Module { // to creation date), so sorting is needed to find the latest embed. let lastMessage = channel.messages.cache .array() - .filter(m => m.author.id === this.client.user?.id) + .filter(m => m.author && m.author.id === this.client.user?.id) .sort((m1, m2) => m2.createdTimestamp - m1.createdTimestamp) .find(m => m.embeds.some(isStatusEmbed)); @@ -364,7 +364,7 @@ export class HelpChanModule extends Module { // Fetch has a stable order, with recent messages first lastMessage = (await channel.messages.fetch({ limit: 5 })) .array() - .filter(m => m.author.id === this.client.user?.id) + .filter(m => m.author && m.author.id === this.client.user?.id) .find(m => m.embeds.some(isStatusEmbed)); if (lastMessage) {