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
14 Replies
- 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:property: Message#messageSnapshots
discord.js@14.21.0
The message snapshots associated with the message referenceso like
message.attachments.some(a.some(m => m.attachments.some(...) || ...
?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
so just to be clear
message.messageSnapshots.first().attachments.some(...)
yes, if you know it's a forward
otherwise .first() will be undefined and it'll error
oh
it doesn't work for regular messages?
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?
oh I see
you can either check the size of the snapshots or check if it's a forward via the message reference
: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 morewhat do you think the cleaner approach would be?
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
ok
ty