Edit components within a container (CV2)
Hi there. Was just wondering if I could get guidance to how I would edit a specific button accessory on a container when calling something like
interaction.update
. Previous you would just modify the component, but now the entire container in itself is a component, and was hoping I wouldn't have to rebuild the container and pass in the change i made. (Also, perhaps adding a tag for components v2 is a good idea now that it's a fresh feature and people may want to target issues specifically for that?)5 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:method: ContainerComponent#toJSON()
[email protected]
Returns the API-compatible JSON for this componenti know spoon feeding is discouraged and i do not want you to, but could you perhaps send a small snippet of what you mean?
i did that initially but typescript complains:
caused by:
Alr fine with that.
components have a optional id property that you can use to identify
yep thanks, Qjuh did mention. Thanks again
also i'm not sure if this is correct, but when logging the container i noticed incremental ID's. Would I need to
setId
to something like 50 to avoid issues or does it not matter
alr thanks. So even if the component is not necessarily the 1st component, giving it an id of 1 is ok
Only got to trying this out today, and what i've done so far:
I notice that it logs this:
-# can share the full log if needed
I've explicitly used setId(1)
on the initial builder itself like so:
And noticed that when I do:
It will always be undefined
since as per the logs, i need to do component.data.data.id
but the 2nd .data
is not recognized by TS. Did i miss a step/perhaps didn't do the correct typing somewhere? Am i maybe just doing it wrong again lol? Thanks!
Even if i want to replace both the TextDisplay and the Accessory?
I initially wanted to just do the accessory, but now want to change the entire section itself
Yea i understand that, but, I would need to do component.data.data.id
for it to find something, since component.data.id
always returns undefined
- and the 2nd .data
is not recognized by ts - i guess my question has shifted a bit now. Does that make sense?
But 2nd approach has a ts error:
@Qjuh Just wanted to apologize. I completely forgot the initial thing you mentioned - toJSON
Adding that fixed everything. That's completely my bad.
For anyone else just joining in:
was the fix