package main import ( "bytes" "encoding/json" "net/http" ) // Webhook is the parent structure fired off to Discord. type Webhook struct { Embeds []Embed `json:"embeds,omitifempty"` } // EmbedField is an individual field being embedded in a message. type EmbedField struct { Name string `json:"name"` Value string `json:"value"` Inline bool `json:"inline"` } // EmbedFooter is the message footer. type EmbedFooter struct { Text string `json:"text"` IconURL string `json:"icon_url"` } // Embed is a set of embedded fields and a footer. type Embed struct { Title string `json:"title"` Description string `json:"description"` URL string `json:"url"` Fields []EmbedField `json:"fields"` Footer EmbedFooter `json:"footer"` } // Send returns a request for a Discord webhook. func Send(whurl string, w Webhook) *http.Request { data, err := json.Marshal(&w) if err != nil { panic(err) } req, err := http.NewRequest(http.MethodPost, whurl, bytes.NewBuffer(data)) if err != nil { panic(err) } req.Header.Set("Content-Type", "application/json") return req } // Validate validates the response from Discord. func Validate(resp *http.Response) error { if resp.StatusCode != http.StatusOK { return NewError(http.StatusOK, resp) } return nil }