Website/discord.go

35 lines
814 B
Go
Raw Permalink Normal View History

2024-08-14 10:43:07 +00:00
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
)
const discordWebhookURL = "YOUR_DISCORD_WEBHOOK_URL" // Replace with your Discord webhook URL
type DiscordWebhookPayload struct {
Content string `json:"content"`
}
func sendDiscordNotification(content string) {
payload := DiscordWebhookPayload{Content: content}
payloadBytes, err := json.Marshal(payload)
if err != nil {
log.Printf("Error marshalling Discord webhook payload: %v", err)
return
}
resp, err := http.Post(discordWebhookURL, "application/json", bytes.NewBuffer(payloadBytes))
if err != nil {
log.Printf("Error sending Discord webhook: %v", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
log.Printf("Unexpected status code from Discord webhook: %d", resp.StatusCode)
}
}