discordgo icon indicating copy to clipboard operation
discordgo copied to clipboard

Unable to Unmarshal Modal Submit Data

Open ankurpalmia opened this issue 1 year ago • 1 comments

When submitting a modal, we receive an InteractionCreate event with following data:

"custom_id": String,
"components": Array of message components

This data is unmarshalled using the following struct present in interactions.go

// ModalSubmitInteractionData contains the data of modal submit interaction.
type ModalSubmitInteractionData struct {
	CustomID   string             `json:"custom_id"`
	Components []MessageComponent `json:"-"`
}

Here, the json for Components is -, due to which the Components array becomes empty after unmarshalling.

This needs to be updated by changing "-" to "components".

ankurpalmia avatar Aug 19 '22 13:08 ankurpalmia

This is intentional. - is set, because MessageComponent is an interface, and encoding/json does not unmarshal into interfaces. To properly unmarshal the Components we have an UnmarshalJSON function for this struct.

FedorLap2006 avatar Aug 19 '22 15:08 FedorLap2006