This repository has been archived on 2022-06-29. You can view files and clone it, but cannot push or open issues or pull requests.
discordrone/message/send_message.go

33 lines
619 B
Go

package message
import (
// stdlib
"bytes"
"encoding/json"
"fmt"
"net/http"
// local
"go.dev.pztrn.name/discordrone/env"
)
// Sends message to Discord.
func sendMessage(message interface{}) error {
webhookURL := fmt.Sprintf("https://discordapp.com/api/webhooks/%s/%s", env.Data.Plugin.Webhook.ID, env.Data.Plugin.Webhook.Token)
b := new(bytes.Buffer)
if err := json.NewEncoder(b).Encode(message); err != nil {
return err
}
resp, err := http.Post(webhookURL, "application/json; charset=utf-8", b)
// We do not need response's body.
resp.Body.Close()
if err != nil {
return err
}
return nil
}