godiscord

package module
v0.0.0-...-7fbd576 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: MIT Imports: 6 Imported by: 0

README

godiscord

A package for the creation and deliver of embeds for Discord

Usage:

package main

import "github.com/aiomonitors/godiscord"

func main() {
    //Create a new embed object
    embed := godiscord.NewEmbed("Title", "Description", "URL")

    //Creates a new field and adds it to the embed
    //boolean represents whether the field is inline or not
    embed.AddField("This is a field", "This is the value", true)

    //Sets the thumbail of the embed
    embed.SetThumbnail("URL")

    //Sets image of embed
    embed.SetImage("URL")

    //Sets color of embed given hexcode
    embed.SetColor("#F1B379")

    //Sets author of embed given name, icon url, and URL
    //Can pass in empty string for IconURL or URL
    embed.SetAuthor("Name", "URL", "IconURL") 
    //also valid
    embed.SetAuthor("Name", "URL", "") 

    //Sets footer of embed given name and IconURL
    //Can pass in empty string for IconURL
    embed.SetFooter("Text", "IconURL")
    //also valid
    embed.SetFooter("Text", "")

    //Send embed to given webhook
    embed.SendToWebhook("Webhook URL")
}

For any questions or problems regarding this package contact me at: Twitter

Email

Personal Site

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	Name    string `json:"name"`
	URL     string `json:"url"`
	IconURL string `json:"icon_url"`
}

Author represents the author of the embed

type Embed

type Embed struct {
	Username  string         `json:"username"`
	AvatarURL string         `json:"avatar_url"`
	Content   string         `json:"content"`
	Embeds    []EmbedElement `json:"embeds"`
}

Embed is a struct representing a Discord embed object

func NewEmbed

func NewEmbed(Title, Description, URL string) Embed

NewEmbed creates a new embed object. Returns Embed.

func (*Embed) AddField

func (e *Embed) AddField(Name, Value string, Inline bool) error

AddField adds a frield to the Embed. Returns an error if the embed was not initialized properly

func (*Embed) SendToWebhook

func (e *Embed) SendToWebhook(Webhook string) error

SendToWebhook sents the Embed to a webhook. Returns error if embed was invalid or there was an error posting to the webhook.

func (*Embed) SetAuthor

func (e *Embed) SetAuthor(Name, URL, IconURL string)

SetAuthor sets the author of the Embed

func (*Embed) SetAvatarURL

func (e *Embed) SetAvatarURL(avatarURL string)

SetAvatarURL sets the Avatar URL of the Embed sender

func (*Embed) SetColor

func (e *Embed) SetColor(color string) error

SetColor takes in a hex code and sets the color of the Embed. Returns an error if the hex is invalid

func (*Embed) SetContent

func (e *Embed) SetContent(content string)

SetContent gives the message a Content value

func (*Embed) SetFooter

func (e *Embed) SetFooter(Text, IconURL string) error

SetFooter sets the footer of the embed. Returns an error if the embed was not initialized properly

func (*Embed) SetImage

func (e *Embed) SetImage(URL string) error

SetImage sets the image of the embed Returns an error if the embed was not initialized properly

func (*Embed) SetThumbnail

func (e *Embed) SetThumbnail(URL string) error

SetThumbnail sets the thumbnail of the embed. Returns an error if the embed was not initialized properly

func (*Embed) SetUsername

func (e *Embed) SetUsername(Name string)

SetUsername sets the username of the Embed sender

type EmbedElement

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

EmbedElement is a struct representing an Embed element of the Embed struct

type Field

type Field struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

Field represents a field in an embed

type Footer struct {
	Text    string `json:"text"`
	IconURL string `json:"icon_url,omitempty"`
}

Footer represents the footer of an embed

type Image

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

Image represents the image of an embed

type Webhook

type Webhook struct {
	URL     string `json:"webhook"`
	IconURL string `json:"icon_url"`
	Text    string `json:"text"`
	Color   string `json:"color"`
}

Webhook represents a webhook

Jump to

Keyboard shortcuts

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