From 99dd235a397f1a89fee223de1a7eb74f12158cf1 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 17 Sep 2024 21:31:26 +0200 Subject: [PATCH] check for a referenced message one time (#137) --- src/events/message/messageCreate.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index 13892ef..2afe9fb 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -65,7 +65,19 @@ export default async (message: Message, client: Client) => { [], ) .map(async ({ message_id, channel }) => { - const quoted_message = await channel.messages.fetch(message_id).catch(() => undefined); + let quoted_message = await channel.messages.fetch(message_id).catch(() => undefined); + + // If it's a reference, we only check for reference once + const message_reference = quoted_message?.reference; + if (message_reference && message_reference.messageId) { + const channel_reference = client.channels.cache.get( + message_reference.channelId, + ) as TextBasedChannel; + + quoted_message = await channel_reference.messages + .fetch(message_reference.messageId) + .catch(() => undefined); + } // If message doesn't exist or empty if (