Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
fix: suppress errors when fetching sticky
Browse files Browse the repository at this point in the history
We don't need to care if the sticky message got deleted some other
way. As such, failing to fetch the message should not bubble up
and block the process. So we can swallow those errors and
proceed with the rest of the logic.
  • Loading branch information
naomi-lgbt committed Jun 6, 2024
1 parent 3fcc9c0 commit 9aa16c1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/modules/sendStickyMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import { errorHandler } from "../utils/errorHandler";
export const sendStickyMessage = async (bot: ExtendedClient) => {
try {
const lastMessage = (
await bot.cache.generalChannel.messages.fetch({
limit: 1,
})
).first();
await bot.cache.generalChannel.messages
.fetch({
limit: 1,
})
.catch(() => null)
)?.first();
if (!lastMessage) {
return;
}
Expand All @@ -24,9 +26,9 @@ export const sendStickyMessage = async (bot: ExtendedClient) => {
}

if (bot.cache.lastSticky) {
const lastSticky = await bot.cache.generalChannel.messages.fetch(
bot.cache.lastSticky
);
const lastSticky = await bot.cache.generalChannel.messages
.fetch(bot.cache.lastSticky)
.catch(() => null);
if (lastSticky) {
await lastSticky.delete();
}
Expand Down

0 comments on commit 9aa16c1

Please sign in to comment.