Check forwarded attachments

Currently we have a system to auto-react to any message that has an attachment However, when a message is forwarded and has an attachment, it doesn't get reacted to. Is there a way to fix this? I have attached the current code to detect if the message has an attachment
message.attachments.some(
a => a.contentType?.startsWith("image/") || a.contentType?.startsWith("video/") || false,
) || message.embeds.some(is_media_link_embed)
message.attachments.some(
a => a.contentType?.startsWith("image/") || a.contentType?.startsWith("video/") || false,
) || message.embeds.some(is_media_link_embed)
14 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
d.js docs
d.js docs3mo ago
:property: Message#messageSnapshots discord.js@14.21.0 The message snapshots associated with the message reference
Perry
PerryOP3mo ago
so like message.attachments.some(a.some(m => m.attachments.some(...) || ...?
Amgelo
Amgelo3mo ago
no, you need to check inside the messageSnapshots a forwarded message by itself is empty, which you already confirmed the data comes from its snapshots field which holds a Collection of "snapshots" (though currently only holds at most 1 snapshot, so you can use .first()), each of which hold some data of the original message, hence why forwards don't update if the original message is edited you'll need to do your checks but checking that snapshot, not the message itself
Perry
PerryOP3mo ago
so just to be clear message.messageSnapshots.first().attachments.some(...)
Amgelo
Amgelo3mo ago
yes, if you know it's a forward otherwise .first() will be undefined and it'll error
Perry
PerryOP3mo ago
oh it doesn't work for regular messages?
Amgelo
Amgelo3mo ago
no, they don't have a message snapshot as I said, snapshots contain the original message's data if there's no original message, what would it contain?
Perry
PerryOP3mo ago
oh I see
Amgelo
Amgelo3mo ago
you can either check the size of the snapshots or check if it's a forward via the message reference
d.js docs
d.js docs3mo ago
:property: Message#reference discord.js@14.21.0 Message reference data :propertysignature: MessageReference#type discord.js@14.21.0 The type of message reference :dtypes: v10: MessageReferenceType - Forward read more
Perry
PerryOP3mo ago
what do you think the cleaner approach would be?
Amgelo
Amgelo3mo ago
well the first is the shorter one, but it has a lot of assumptions about how discord currently works, it may not work well in the future if discord adds more stuff (eg more reference types) the second one is the verbose but "safer" one
Perry
PerryOP3mo ago
ok ty

Did you find this page helpful?