webhook

package
v0.0.0-...-23c838b Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrParseWebhook = errors.New("failed to parse discord webhook url")

ErrParseWebhook represents error when parsing url, id, or token

Functions

This section is empty.

Types

type APIError

type APIError struct {
	HTTPResponse int    `json:"http_response"`
	Code         int    `json:"code"`
	Message      string `json:"message"`
}

APIError represents discord answer to the request if it went wrong. https://discord.com/developers/docs/topics/opcodes-and-status-codes

func (*APIError) Error

func (e *APIError) Error() string

Error implements `error` interface.

type Embed

type Embed struct {
	// Title of embed
	Title string `json:"title"`
	// Type of embed (always "rich" for webhook embeds)
	Type string `json:"type"`
	// Description of embed
	Description string `json:"description"`
	// URL of embed
	URL string `json:"url"`
	// Timestamp of embed content. Should be in ISO8601 format.
	Timestamp string `json:"timestamp"`
	// Color code of the embed
	Color     int           `json:"color"`
	Footer    *EmbedFooter  `json:"footer"`
	Image     *EmbedImage   `json:"image"`
	Thumbnail *EmbedImage   `json:"thumbnail"`
	Video     *EmbedVideo   `json:"video"`
	Author    *EmbedAuthor  `json:"author"`
	Fields    []*EmbedField `json:"fields"`
}

Embed represents discord embed. https://discord.com/developers/docs/resources/channel#embed-object

type EmbedAuthor

type EmbedAuthor struct {
	// Name of author
	Name string `json:"name"`
	// URL of author
	URL string `json:"url"`
	// URL of author icon (only supports http(s) and attachments)
	IconURL string `json:"icon_url"`
}

EmbedAuthor represents author of the embed

type EmbedField

type EmbedField struct {
	// Name of the field. Required.
	Name string `json:"name"`
	// Value of the field. Required.
	Value string `json:"value"`
	// Whether or not this field should display inline.
	Inline bool `json:"inline"`
}

EmbedField represents embed field (max. 25)

type EmbedFooter

type EmbedFooter struct {
	// Footer text. Required.
	Text string `json:"text"`
	// URL of footer icon (only supports http(s) and attachments)
	IconURL string `json:"icon_url"`
}

EmbedFooter represents embed's footer

type EmbedImage

type EmbedImage struct {
	// URL source of image (only supports http(s) and attachments)
	URL string `json:"url"`
	// Height of image
	Height int `json:"height"`
	// Width of image
	Width int `json:"width"`
}

EmbedImage represents Image that would be inside of the embed

type EmbedVideo

type EmbedVideo struct {
	// URL source of video
	URL string `json:"url"`
	// Height of video
	Height int `json:"height"`
	// Width of video
	Width int `json:"width"`
}

EmbedVideo represents Video that would be inside of the embed

type Message

type Message struct {
	// Content is a message body up to 2000 characters.
	Content   string   `json:"content"`
	Username  string   `json:"username"`
	AvatarURL string   `json:"avatar_url"`
	TTS       bool     `json:"tts"`
	Embeds    []*Embed `json:"embeds"`
}

Message represents a message to send using webhook. When sending a message there must be one of content or embeds.

type Update

type Update struct {
	Name string `json:"name"`
	// Avatar is a base64 encoded image. https://discord.com/developers/docs/reference#image-data
	Avatar string `json:"avatar"`
}

Update is used to update webhooks using tokens. Only name and avatar can be updated.

type Webhook

type Webhook struct {
	ID        string `json:"id"`
	GuildID   string `json:"guild_id"`
	ChannelID string `json:"channel_id"`
	Name      string `json:"name"`
	Avatar    string `json:"avatar"`
	Token     string `json:"token"`
}

Webhook is a representation of discord webhooks

func FromIDAndToken

func FromIDAndToken(id string, token string) (webhook *Webhook, err error)

FromIDAndToken parses id and token and returns Webhook struct.

func FromURL

func FromURL(webhookURL string) (webhook *Webhook, err error)

FromURL parses URL and returns Webhook struct.

func (*Webhook) Delete

func (w *Webhook) Delete() error

Delete deletes webhook from discord.

func (*Webhook) Get

func (w *Webhook) Get() error

Get gets information about webhook. Useful to get name, guild and channel IDs etc.

func (*Webhook) Modify

func (w *Webhook) Modify(update *Update) error

Modify modifies webhook at the client and discord side.

func (*Webhook) SendFile

func (w *Webhook) SendFile(file []byte, filename string, message *Message) error

SendFile sends file with message to webhook

func (*Webhook) SendMessage

func (w *Webhook) SendMessage(message *Message) error

SendMessage sends message to webhook

func (*Webhook) URL

func (w *Webhook) URL() string

URL returns discord url of the webhook

Jump to

Keyboard shortcuts

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