Created
June 19, 2020 17:29
-
-
Save troke12/1dcae1f46ef95d535fc02823b46275e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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