Skip to content

A simplistic Discord webhook API client with limited feature support

License

Notifications You must be signed in to change notification settings

SebastiaanPasterkamp/go-discordwebhook

Repository files navigation

go-discordwebhook

A simplistic Discord webhook API client with limited feature support

Usage

import (
	"encoding/json"
	"log"
	"os"

	discord "github.com/SebastiaanPasterkamp/go-discordwebhook"
)

func example() {
	d, err := discord.NewFromEnv("DISCORD_URL")
	if err != nil {
		log.Fatalf("Failed to initialize discord webhook client: %v", err)
	}

	m := discord.Message{
		Content:   "This is the body",
		Username:  "example",
		AvatarURL: "https://avatars.githubusercontent.com/u/26205277?s=64&v=4",
		Embeds: []discord.Embed{
			{
				Title:       "discord webhook client",
				URL:         "https://github.com/SebastiaanPasterkamp/go-discordwebhook",
				Type:        discord.EmbedRich,
				Description: "Hello *discord*",
				Color:       discord.ColorBlue,
			},
		},
	}

	stdout := json.NewEncoder(os.Stdout)

	reply, fail, err := d.Send(m, true)
	if err != nil {
		stdout.Encode(fail)
		log.Fatalf("Failed to send message to discord: %v", err)
	}

	if fail != nil {
		stdout.Encode(fail)
		log.Println("Error response from discord")
		os.Exit(fail.Code)
	}

	if reply != nil {
		stdout.Encode(reply)
	}
}

About

A simplistic Discord webhook API client with limited feature support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages