Skip to content

Instantly share code, notes, and snippets.

@troke12
Created June 19, 2020 17:29
Show Gist options
  • Save troke12/1dcae1f46ef95d535fc02823b46275e1 to your computer and use it in GitHub Desktop.
Save troke12/1dcae1f46ef95d535fc02823b46275e1 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
)
var cookies string
func main() {
sendwebhook()
}
var client = &http.Client{}
type Author struct {
Name string `json:"name"`
URL string `json:"url"`
IconURL string `json:"icon_url"`
}
//Footer is the Bottom of the Webhook
type Footer struct {
Text string `json:"text"`
IconURL string `json:"icon_url"`
}
//Embeds is the Overall Formatting of the Webhook
type Embeds struct {
Title string `json:"title"`
Description string `json:"description"`
URL string `json:"url"`
Color int `json:"color"`
Author Author `json:"author"`
Footer Footer `json:"footer"`
Timestamp time.Time `json:"timestamp"`
}
//Webhook is the execution of the webhook itself
type Webhook struct {
Author []Author `json:"author"`
Embeds []Embeds `json:"embeds"`
}
func sendwebhook() {
client := &http.Client{}
t := time.Now()
W := Webhook{
Author: []Author{
Author{
Name: "Ochi",
URL: "github.com",
IconURL: "troke.id/logo.png",
},
},
Embeds: []Embeds{
Embeds{
Title: "Woi testbruh moment",
URL: "google.com",
Color: 9297294,
Timestamp: t,
Footer: Footer{Text: "Bruh", IconURL: "troke.id/favicon.ico"}
,
},
},
}
webhookReq, err := json.Marshal(W)
req, err := http.NewRequest("POST", "DISCORD_WEBHOOK_URL", bytes.NewBuffer
(webhookReq))
req.Header.Add("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Print(err)
}
if resp.StatusCode == http.StatusNoContent {
//No content, or 204, means it worked.
fmt.Println("success")
} else {
//Else print the error and you see what you've done wrong.
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Print(err)
}
bodyString := string(bodyBytes)
fmt.Println(bodyString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment