Update interaction message appending a new container
Hey! I'd like to know if it's possible to do an interaction.update and appending a new container without changing or removing the original one,
I had some tries but I'm having some troubles because the original container has a file inside and the message also have an actionrow with buttons
I was wondering if there's a good method to do that
34 Replies
Yea. You can access the old message components with
interaction.message.components
Prob shouldn’t directly mutate it thoalr what about the file? cause i got the file field which is causing some issues i guess
Wdym?
As you can see I have a FileComponent here and when I try update with let's say
components: [...interaction.message.components[0], newContainer] I get data.components[0].components[6].file.url[UNFURLED_MEDIA_ITEM_MUST_USE_ATTACHMENT_PROTOCOL]: This UnfurledMediaItem does not support arbitrary external urls. You must use the "attachment://" reference system.Why are you expanding the first component?
uh
That should be an error tbh
i should not?
You wrote
[ ...interaction.message.components[0], ?actually wait let me try
I'm doing this now
and I'm getting
data.components[0][MODEL_TYPE_CONVERT]: Expected an object/dictionary.Now you have
[ components, ok i see what you mean
so i should ...originalComponents
Yea
And I'm getting the file error
data.components[0].components[6].file.url[UNFURLED_MEDIA_ITEM_MUST_USE_ATTACHMENT_PROTOCOL]: This UnfurledMediaItem does not support arbitrary external urls. You must use the attachment:// reference system.
Should I pass the files[] again?It should be keeping its attachments
Problem is that the url in the File component got replaced with the Discord cdn one
Can you confirm by logging
originalComponents[0].components[6].file?Yep
Was the url originally
attachment://filename.pdf?yes
Good thing is that it kept its filename
You would just have to iterate through each component just to fix it though, if you want it to work for every case
wouldn't it break if i hardcode the url tho? cause now it has the expire stuff params
You shouldn’t have reupload the files, it’s still on the message
It’s just that Discord changed the urls to https when it provided the message
You just need the filename to change the urls back to attachment://
oh I see
path.basename from the node:path module will help you extract the name
Am I doing this wrong?
The console log returns
But I'm still getting the same error as befor
I don’t think FileComponents has a name prop
Okay I was writing to the wrong object,
Now I changed it to
subcomp.file.url = "attachment://"
but it's read only
TypeError: Cannot set property url of #<UnfurledMediaItem> which has only a getterOh right, you have to convert to builders first
Just map and add in the createComponent call
const builder = createComponentBuilder(comp.toJSON());wait you mean only for the file or
I don’t think you can just convert the file to a builder
Not sure tbh
Misspelled the function name there
Umm not sure i did that good, sill getting
data.components[0].components[6].file.url[UNFURLED_MEDIA_ITEM_MUST_USE_ATTACHMENT_PROTOCOL]: This UnfurledMediaItem does not support arbitrary external urls. You must use the attachment:// reference system.
So I'm not sure it's even modifying that tbhYea, easier just to map everything
map instead of the first forEach
yeah actually im totally doing this wrong cause forEach wont let me to modify the original object
just realized lol
Alright, now it works 😄
Posting the working code for the posterity 🙂
Thank you so much Chewinky!
You don’t need to do it for the File component btw
Oh nvm, I see how you did it
You replaced the entire components of Container