discord

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Discord Webhooks for Go

High-level implementation of methods on Discord webhooks in Go, supporting multipart uploads

Usage

Import the module into your existing Go project with:

go get github.com/latte-soft/discord-webhooks-go

Example

To run the full example (replacing with your own Discord Webhook URL and token):

go run github.com/latte-soft/discord-webhooks-go/_examples/full "https://discord.com/api/webhooks/123/1234567890"

See for examples usage: _examples/full/main.go

Screenshot of example below

License

See file: LICENSE

BSD 3-Clause License

Copyright (c) 2024 Latte Softworks <https://latte.to>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
   contributors may be used to endorse or promote products derived from
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteMessage

func DeleteMessage(webhookUrl string, messageId string, queryParams *QueryParams) (err error)

func EditMessage

func EditMessage(webhookUrl string, messageId string, message *Message) (err error)

REQUIRES AN APPLICATION-OWNED WEBHOOK

func PostMessage

func PostMessage(webhookUrl string, message *Message) (messageId *string, err error)

Types

type AllowedMentions

type AllowedMentions struct {
	Parse *[]string `json:"parse,omitempty"`
	Users *[]string `json:"users,omitempty"`
	Roles *[]string `json:"roles,omitempty"`
}

type Embed

type Embed struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Url         string `json:"url,omitempty"`
	Timestamp   string `json:"timestamp,omitempty"`
	Color       uint32 `json:"color,omitempty"`

	Footer    *EmbedFooter    `json:"footer,omitempty"`
	Image     *EmbedImage     `json:"image,omitempty"`
	Thumbnail *EmbedThumbnail `json:"thumbnail,omitempty"`
	Video     *EmbedVideo     `json:"video,omitempty"`
	Provider  *EmbedProvider  `json:"provider,omitempty"`
	Author    *EmbedAuthor    `json:"author,omitempty"`

	Fields *[]EmbedField `json:"fields,omitempty"`
}

type EmbedAuthor

type EmbedAuthor struct {
	Name         string `json:"name"`
	Url          string `json:"url,omitempty"`
	IconUrl      string `json:"icon_url,omitempty"`
	ProxyIconurl string `json:"proxy_icon_url,omitempty"`
}

type EmbedField

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

type EmbedFooter

type EmbedFooter struct {
	Text         string `json:"text"`
	IconUrl      string `json:"icon_url,omitempty"`
	ProxyIconUrl string `json:"proxy_icon_url,omitempty"`
}

type EmbedImage

type EmbedImage struct {
	Url      string `json:"url"`
	ProxyUrl string `json:"proxy_url,omitempty"`
	Height   int    `json:"height,omitempty"`
	Width    int    `json:"width,omitempty"`
}

type EmbedProvider

type EmbedProvider struct {
	Name string `json:"name,omitempty"`
	Url  string `json:"url,omitempty"`
}

type EmbedThumbnail

type EmbedThumbnail = EmbedImage

Equivalent to `EmbedImage` struct spec

type EmbedVideo

type EmbedVideo = EmbedImage

type File

type File struct {
	Name string
	Data *[]byte
}

For multipart/form-data uploads

type Message

type Message struct {
	Files       *[]File      `json:"-"`
	QueryParams *QueryParams `json:"-"`

	Content    string `json:"content,omitempty"`
	Username   string `json:"username,omitempty"`
	AvatarUrl  string `json:"avatar_url,omitempty"`
	TTS        bool   `json:"tts,omitempty"`
	ThreadName string `json:"thread_name,omitempty"`

	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`

	Embeds *[]Embed `json:"embeds,omitempty"`
}

https://discord.com/developers/docs/resources/webhook#execute-webhook

type MessageEdit

type MessageEdit struct {
	Content string `json:"content,omitempty"`

	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`

	Embeds *[]Embed `json:"embeds,omitempty"`
}

https://discord.com/developers/docs/resources/webhook#edit-webhook-message Derivative of `discord.Message` though, yeah

type QueryParams

type QueryParams struct {
	//Wait     bool
	ThreadId string
}

Because yeah

type WebhookInfo

type WebhookInfo 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"`
	Url       string `json:"url"`

	// Application-owned webhooks only
	ApplicationId string `json:"application_id"`

	Type WebhookType `json:"type"`
}

https://discord.com/developers/docs/resources/webhook#get-webhook-with-token (With no `user` obj) https://discord.com/developers/docs/resources/webhook#webhook-object

func GetWebhookInfo

func GetWebhookInfo(webhookUrl string) (webhookInfo *WebhookInfo, err error)

type WebhookType

type WebhookType int

https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types

const (
	WebhookTypeIncoming        WebhookType = 1
	WebhookTypeChannelFollower WebhookType = 2
	WebhookTypeApplication     WebhookType = 3
)

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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