discordwebhook

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 7 Imported by: 3

README

discord-webhook-golang

Allows for easy webhook sending through discord's webhook API.

Installation

go get github.com/bensch777/discord-webhook-golang

Code Example

package main

import (
    "encoding/json"
    "log"
    "time"
    "github.com/bensch777/discord-webhook-golang"
)

func main() {

    var webhookurl = "https://discord.com/api/webhooks/1069721907429122218/AXcbveVUfztv5Xh5y5uOp....."

    embed := discordwebhook.Embed{
        Title:     "Example Webhook",
        Color:     15277667,
        Url:       "https://avatars.githubusercontent.com/u/6016509?s=48&v=4",
        Timestamp: time.Now(),
        Thumbnail: discordwebhook.Thumbnail{
            Url: "https://avatars.githubusercontent.com/u/6016509?s=48&v=4",
        },
        Author: discordwebhook.Author{
            Name:     "Author Name",
            Icon_URL: "https://avatars.githubusercontent.com/u/6016509?s=48&v=4",
        },
        Fields: []discordwebhook.Field{
            discordwebhook.Field{
                Name:   "Field 1",
                Value:  "Field Value 1",
                Inline: true,
            },
            discordwebhook.Field{
                Name:   "Field 2",
                Value:  "Field Value 2",
                Inline: true,
            },
            discordwebhook.Field{
                Name:   "Field 3",
                Value:  "Field Value 3",
                Inline: false,
            },
        },
        Footer: discordwebhook.Footer{
            Text:     "Footer Text",
            Icon_url: "https://avatars.githubusercontent.com/u/6016509?s=48&v=4",
        },
    }

    SendEmbed(webhookurl, embed)

}


func SendEmbed(link string, embeds discordwebhook.Embed) error {

    hook := discordwebhook.Hook{
        Username:   "Captain Hook",
        Avatar_url: "https://avatars.githubusercontent.com/u/6016509?s=48&v=4",
        Content:    "Message",
        Embeds:     []discordwebhook.Embed{embeds},
    }

    payload, err := json.Marshal(hook)
    if err != nil {
        log.Fatal(err)
    }
    err = discordwebhook.ExecuteWebhook(link, payload)
    return err

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteWebhook

func ExecuteWebhook(link string, data []byte) error

func SendEmbed

func SendEmbed(link string, embeds Embed) error

Types

type Attachment

type Attachment struct {
	Id          string `json:"id"`
	Description string `json:"description"`
	Filename    string `json:"filename"`
}

type Author

type Author struct {
	Name     string `json:"name"`
	Icon_URL string `json:"icon_url"`
	Url      string `json:"url"`
}

type Embed

type Embed struct {
	Title       string    `json:"title"`
	Url         string    `json:"url"`
	Description string    `json:"description"`
	Color       int       `json:"color"`
	Thumbnail   Thumbnail `json:"thumbnail"`
	Footer      Footer    `json:"footer"`
	Fields      []Field   `json:"fields"`
	Timestamp   time.Time `json:"timestamp"`
	Author      Author    `json:"author"`
}

type Field

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

type Hook

type Hook struct {
	Username    string       `json:"username"`
	Avatar_url  string       `json:"avatar_url"`
	Content     string       `json:"content"`
	Embeds      []Embed      `json:"embeds"`
	Attachments []Attachment `json:"attachments"`
}

type Thumbnail

type Thumbnail struct {
	Url string `json:"url"`
}

Jump to

Keyboard shortcuts

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