discordgo
discordgo copied to clipboard
Unable to Unmarshal Modal Submit Data
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"
.
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.