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

Commit

Permalink
refactor(message-link-reaction.event.ts): simplify message and channe…
Browse files Browse the repository at this point in the history
…l fetching logic and improve error handling
  • Loading branch information
Bluzzi committed May 31, 2023
1 parent 6eace50 commit cd001b3
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/events/message-link-reaction/message-link-reaction.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ export const execute: EventExecute<"messageCreate"> = async(message) => {

if (!ids.length) return;

// Get channel and message instances :
let messageQuoted: Message;
const guildQuoted = await client.guilds.fetch(ids[0][0]);
const channelQuoted = await guildQuoted.channels.fetch(ids[1][0]);

try {
const guildQuoted = await client.guilds.fetch(ids[0][0]);
const channelQuoted = await guildQuoted.channels.fetch(ids[1][0]);

if (!channelQuoted || !channelQuoted.isTextBased()) throw new Error("Channel not found");

messageQuoted = await channelQuoted.messages.fetch(ids[2][0]);
} catch (e) {
logger.error(`Error while getting message: ${String(e)}`);
if (!channelQuoted || !channelQuoted.isTextBased()) {
logger.error("Error while getting message: channel not found");
return;
}

const messageQuoted = await channelQuoted.messages.fetch(ids[2][0]);

messages.push({ url, message: messageQuoted });
}

Expand Down

0 comments on commit cd001b3

Please sign in to comment.