@@ -135,10 +135,7 @@ func (m *Message) UnmarshalJSON(data []byte) error {
135
135
* m = Message (v .message )
136
136
137
137
if len (v .Components ) > 0 {
138
- m .Components = make ([]ContainerComponent , len (v .Components ))
139
- for i := range v .Components {
140
- m .Components [i ] = v .Components [i ].Component .(ContainerComponent )
141
- }
138
+ m .Components = unmarshalComponents (v .Components )
142
139
}
143
140
144
141
if m .Member != nil && m .GuildID != nil {
@@ -428,15 +425,38 @@ type MessageSnapshot struct {
428
425
}
429
426
430
427
type PartialMessage struct {
431
- Type MessageType `json:"type"`
432
- Content string `json:"content,omitempty"`
433
- Embeds []Embed `json:"embeds,omitempty"`
434
- Attachments []Attachment `json:"attachments"`
435
- CreatedAt time.Time `json:"timestamp"`
436
- EditedTimestamp * time.Time `json:"edited_timestamp"`
437
- Flags MessageFlags `json:"flags"`
438
- Mentions []User `json:"mentions"`
439
- MentionRoles []snowflake.ID `json:"mention_roles"`
428
+ Type MessageType `json:"type"`
429
+ Content string `json:"content,omitempty"`
430
+ Embeds []Embed `json:"embeds,omitempty"`
431
+ Attachments []Attachment `json:"attachments"`
432
+ CreatedAt time.Time `json:"timestamp"`
433
+ EditedTimestamp * time.Time `json:"edited_timestamp"`
434
+ Flags MessageFlags `json:"flags"`
435
+ Mentions []User `json:"mentions"`
436
+ MentionRoles []snowflake.ID `json:"mention_roles"`
437
+ Stickers []Sticker `json:"stickers"`
438
+ StickerItems []MessageSticker `json:"sticker_items,omitempty"`
439
+ Components []ContainerComponent `json:"components,omitempty"`
440
+ }
441
+
442
+ func (m * PartialMessage ) UnmarshalJSON (data []byte ) error {
443
+ type partialMessage PartialMessage
444
+ var v struct {
445
+ Components []UnmarshalComponent `json:"components"`
446
+ partialMessage
447
+ }
448
+
449
+ if err := json .Unmarshal (data , & v ); err != nil {
450
+ return err
451
+ }
452
+
453
+ * m = PartialMessage (v .partialMessage )
454
+
455
+ if len (v .Components ) > 0 {
456
+ m .Components = unmarshalComponents (v .Components )
457
+ }
458
+
459
+ return nil
440
460
}
441
461
442
462
// MessageInteraction is sent on the Message object when the message is a response to an interaction
@@ -515,3 +535,11 @@ type MessageCall struct {
515
535
Participants []snowflake.ID `json:"participants"`
516
536
EndedTimestamp * time.Time `json:"ended_timestamp"`
517
537
}
538
+
539
+ func unmarshalComponents (components []UnmarshalComponent ) []ContainerComponent {
540
+ containerComponents := make ([]ContainerComponent , len (components ))
541
+ for i := range components {
542
+ containerComponents [i ] = components [i ].Component .(ContainerComponent )
543
+ }
544
+ return containerComponents
545
+ }
0 commit comments