Skip to content

Commit a7d08a9

Browse files
authored
add Message field to ModalSubmitInteraction (#455)
1 parent 0db201a commit a7d08a9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

discord/interaction_modal_submit.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ var (
99
type ModalSubmitInteraction struct {
1010
baseInteraction
1111
Data ModalSubmitInteractionData `json:"data"`
12+
// Message is only present if the modal was triggered from a button
13+
Message *Message `json:"message,omitempty"`
1214
}
1315

1416
func (i *ModalSubmitInteraction) UnmarshalJSON(data []byte) error {
1517
var interaction struct {
1618
rawInteraction
17-
Data ModalSubmitInteractionData `json:"data"`
19+
Data ModalSubmitInteractionData `json:"data"`
20+
Message *Message `json:"message,omitempty"`
1821
}
1922
if err := json.Unmarshal(data, &interaction); err != nil {
2023
return err
@@ -43,13 +46,19 @@ func (i *ModalSubmitInteraction) UnmarshalJSON(data []byte) error {
4346
}
4447

4548
i.Data = interaction.Data
49+
i.Message = interaction.Message
50+
if i.Message != nil {
51+
i.Message.GuildID = i.baseInteraction.guildID
52+
}
4653
return nil
4754
}
4855

4956
func (i ModalSubmitInteraction) MarshalJSON() ([]byte, error) {
5057
return json.Marshal(struct {
5158
rawInteraction
5259
Data ModalSubmitInteractionData `json:"data"`
60+
// Message is only present if the modal was triggered from a button
61+
Message *Message `json:"message,omitempty"`
5362
}{
5463
rawInteraction: rawInteraction{
5564
ID: i.id,
@@ -71,7 +80,8 @@ func (i ModalSubmitInteraction) MarshalJSON() ([]byte, error) {
7180
Context: i.context,
7281
AttachmentSizeLimit: i.attachmentSizeLimit,
7382
},
74-
Data: i.Data,
83+
Data: i.Data,
84+
Message: i.Message,
7585
})
7686
}
7787

0 commit comments

Comments
 (0)