dcwebhook

package module
v0.0.0-...-776a1d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

README

discord-go-webhook

Go Lang library to send messages to Discord via Incoming Webhooks.

This package uses the framework from the slack-go-webhook package: https://github.com/ashwanthkumar/slack-go-webhook

Usage

package main
import (
	"fmt"
	"github.com/sstansong/discord-go-webhook"
)

func main() {
	webhookUrl := "https://discordapp.com/api/webhooks/token/ID"
	payload := dcwebhook.Payload{
		Username:"root",
		TTS:false,
		IconUrl:"https://github.io",
		Content:"Hello from <github.com/sstansong/discord-go-webhook>, a Go-Lang library to send discord webhook messages.\n<https://golangschool.com/wp-content/uploads/golang-teach.jpg|golang-img>",
		Embeds: []dcwebhook.Embed{
			{
				Title:"",
				URL:"",
				Description:"",
				Color:0,
				Author:,
				Fields:[]dcwebhook.Field{},
				Image:,
				Thumbnail:,
				Footer:,
			},
		},
	}

	err := dcwebhook.Send(webhookUrl, "", payload)
	if len(err) > 0 {
		fmt.Printf("error: %s\n", err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(webhookUrl string, proxy string, payload Payload) []error

Types

type Author

type Author struct {
	Name    string `json:"name,omitempty"`
	URL     string `json:"url,omitempty"`
	IconUrl string `json:"icon_url,omitempty"`
}

type Embed

type Embed struct {
	Title       string    `json:"title,omitempty"`
	URL         string    `json:"url,omitempty"`
	Description string    `json:"description,omitempty"`
	Color       int       `json:"color,omitempty"`
	Author      Author    `json:"author,omitempty"`
	Fields      []Field   `json:"fields,omitempty"`
	Image       Image     `json:"image,omitempty"`
	Thumbnail   Thumbnail `thumbnail:"image,omitempty"`
	Footer      Footer    `json:"footer,omitempty"`
}

func (*Embed) AddFieldtoEmbed

func (embed *Embed) AddFieldtoEmbed(field Field) *Embed

type Field

type Field struct {
	Name   string `json:"name,omitempty"`
	Value  string `json:"value,omitempty"`
	Inline bool   `json:"inline,omitempty"`
}
type Footer struct {
	Text    string `json:"text,omitempty"`
	IconUrl string `json:"icon_url,omitempty"`
}

type Image

type Image struct {
	URL string `json:"url,omitempty"`
}

type Payload

type Payload struct {
	Username string  `json:"username,omitempty"`
	TTS      bool    `json:"tts,omitempty"`
	IconUrl  string  `json:"avatar_url,omitempty"`
	Content  string  `json:"content,omitempty"`
	Embeds   []Embed `json:"embeds,omitempty"`
}

func (*Payload) AddEmbed

func (payload *Payload) AddEmbed(embed Embed) *Payload

type Thumbnail

type Thumbnail struct {
	URL string `json:"thumbnail,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL