diff --git a/discord/message.go b/discord/message.go index dcf830e8..b9ce4aae 100644 --- a/discord/message.go +++ b/discord/message.go @@ -135,10 +135,7 @@ func (m *Message) UnmarshalJSON(data []byte) error { *m = Message(v.message) if len(v.Components) > 0 { - m.Components = make([]ContainerComponent, len(v.Components)) - for i := range v.Components { - m.Components[i] = v.Components[i].Component.(ContainerComponent) - } + m.Components = unmarshalComponents(v.Components) } if m.Member != nil && m.GuildID != nil { @@ -428,15 +425,38 @@ type MessageSnapshot struct { } type PartialMessage struct { - Type MessageType `json:"type"` - Content string `json:"content,omitempty"` - Embeds []Embed `json:"embeds,omitempty"` - Attachments []Attachment `json:"attachments"` - CreatedAt time.Time `json:"timestamp"` - EditedTimestamp *time.Time `json:"edited_timestamp"` - Flags MessageFlags `json:"flags"` - Mentions []User `json:"mentions"` - MentionRoles []snowflake.ID `json:"mention_roles"` + Type MessageType `json:"type"` + Content string `json:"content,omitempty"` + Embeds []Embed `json:"embeds,omitempty"` + Attachments []Attachment `json:"attachments"` + CreatedAt time.Time `json:"timestamp"` + EditedTimestamp *time.Time `json:"edited_timestamp"` + Flags MessageFlags `json:"flags"` + Mentions []User `json:"mentions"` + MentionRoles []snowflake.ID `json:"mention_roles"` + Stickers []Sticker `json:"stickers"` + StickerItems []MessageSticker `json:"sticker_items,omitempty"` + Components []ContainerComponent `json:"components,omitempty"` +} + +func (m *PartialMessage) UnmarshalJSON(data []byte) error { + type partialMessage PartialMessage + var v struct { + Components []UnmarshalComponent `json:"components"` + partialMessage + } + + if err := json.Unmarshal(data, &v); err != nil { + return err + } + + *m = PartialMessage(v.partialMessage) + + if len(v.Components) > 0 { + m.Components = unmarshalComponents(v.Components) + } + + return nil } // MessageInteraction is sent on the Message object when the message is a response to an interaction @@ -515,3 +535,11 @@ type MessageCall struct { Participants []snowflake.ID `json:"participants"` EndedTimestamp *time.Time `json:"ended_timestamp"` } + +func unmarshalComponents(components []UnmarshalComponent) []ContainerComponent { + containerComponents := make([]ContainerComponent, len(components)) + for i := range components { + containerComponents[i] = components[i].Component.(ContainerComponent) + } + return containerComponents +}