From f39d983835df6fbf728eb18b18dee62f10c312ec Mon Sep 17 00:00:00 2001 From: Carson Hoffman Date: Tue, 10 Aug 2021 21:40:36 -0400 Subject: [PATCH] Add more safety around message reference misuse --- message.go | 4 +++- restapi.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/message.go b/message.go index b8cd8e4fe..63ba96c4a 100644 --- a/message.go +++ b/message.go @@ -120,7 +120,9 @@ type Message struct { // Is sent with Rich Presence-related chat embeds Application *MessageApplication `json:"application"` - // MessageReference contains reference data sent with crossposted messages + // MessageReference contains reference data sent with crossposted or reply messages. + // This does not contain the reference *to* this message; this is for when *this* message references another. + // To generate a reference to this message, use (*Message).Reference(). MessageReference *MessageReference `json:"message_reference"` // The flags of the message, which describe extra features of a message. diff --git a/restapi.go b/restapi.go index 31846d967..9c1734789 100644 --- a/restapi.go +++ b/restapi.go @@ -1612,6 +1612,9 @@ func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) // content : The message to send. // reference : The message reference to send. func (s *Session) ChannelMessageSendReply(channelID string, content string, reference *MessageReference) (*Message, error) { + if reference == nil { + return nil, fmt.Errorf("reply attempted with nil message reference") + } return s.ChannelMessageSendComplex(channelID, &MessageSend{ Content: content, Reference: reference,