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

29 lines
559 B
Go
Raw Normal View History

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
}
_, err := http.Post(webhookURL, "application/json; charset=utf-8", b)
if err != nil {
return err
}
return nil
}