Skip to content

Commit d29c358

Browse files
committed
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).
1 parent 14bf8f8 commit d29c358

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/modules/helpchan.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,15 @@ export class HelpChanModule extends Module {
356356
// to creation date), so sorting is needed to find the latest embed.
357357
let lastMessage = channel.messages.cache
358358
.array()
359-
.filter(m => m.author.id === this.client.user?.id)
359+
.filter(m => m.author && m.author.id === this.client.user?.id)
360360
.sort((m1, m2) => m2.createdTimestamp - m1.createdTimestamp)
361361
.find(m => m.embeds.some(isStatusEmbed));
362362

363363
if (!lastMessage)
364364
// Fetch has a stable order, with recent messages first
365365
lastMessage = (await channel.messages.fetch({ limit: 5 }))
366366
.array()
367-
.filter(m => m.author.id === this.client.user?.id)
367+
.filter(m => m.author && m.author.id === this.client.user?.id)
368368
.find(m => m.embeds.some(isStatusEmbed));
369369

370370
if (lastMessage) {

0 commit comments

Comments
 (0)