Skip to content

Commit cf6f370

Browse files
committed
fix: clear the cache to prevent the error when closing a help channel after a user has left the server
1 parent 103f4db commit cf6f370

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/modules/helpchan.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,27 @@ export class HelpChanModule extends Module {
364364
else askHelpChannel.send(newMessageText);
365365
}
366366

367+
private async getChannelMember(channel: TextChannel) {
368+
return (
369+
HelpUser.findOneOrFail({
370+
channelId: channel.id,
371+
})
372+
.then(helpUser => {
373+
// Clear from the cache in case they've left the server
374+
channel.guild.members.cache.delete(helpUser.userId);
375+
return channel.guild.members.fetch({
376+
user: helpUser.userId,
377+
});
378+
})
379+
// Do nothing, member left the guild
380+
.catch(() => undefined)
381+
);
382+
}
383+
367384
private async markChannelAsDormant(channel: TextChannel) {
368385
this.busyChannels.add(channel.id);
369386

370-
const memberPromise = HelpUser.findOneOrFail({
371-
channelId: channel.id,
372-
})
373-
.then(helpUser =>
374-
channel.guild.members.fetch({
375-
user: helpUser.userId,
376-
}),
377-
)
378-
// Do nothing, member left the guild
379-
.catch(() => undefined);
387+
const memberPromise = this.getChannelMember(channel);
380388

381389
const pinnedPromise = channel.messages.fetchPinned();
382390

0 commit comments

Comments
 (0)