godishook

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 14 Imported by: 0

README

godishook

A modern, stdlib-only Go library for sending Discord webhooks.

  • Fluent builders for messages, embeds, and polls
  • Every Execute Webhook field
  • Multipart file uploads
  • Token-based get / edit / delete of sent messages
  • Components v1 (action rows, buttons, selects) and Components V2
  • context.Context on all network calls; injectable *http.Client

Install

go get github.com/ilbinek/godishook

Quick start

package main

import (
	"context"
	"log"
	"os"

	"github.com/ilbinek/godishook"
)

func main() {
	client, err := godishook.NewFromURL(os.Getenv("DISCORD_WEBHOOK_URL"))
	if err != nil {
		log.Fatal(err)
	}

	msg, err := client.Send(context.Background(), godishook.Message().
		Content("Deploy finished").
		Username("CI").
		Embed(godishook.NewEmbed().
			Title("Build #42").
			Description("All green").
			Color(0x57F287).
			Field("Commit", "`abc123`", true).
			Footer("godishook", "")))
	if err != nil {
		log.Fatal(err)
	}
	log.Println("sent", msg.ID)
}

Message() defaults to wait=true, so Discord returns the created message (same ergonomics as discord.js).

Struct style

client.Send(ctx, &godishook.Payload{
	Content:  "hi",
	Username: "bot",
	Embeds:   []*godishook.Embed{{Title: "Hello"}},
})

Files

file, err := godishook.FileFromPath("report.pdf")
if err != nil {
	log.Fatal(err)
}
client.Send(ctx, godishook.Message().
	Content("Report attached").
	File(file).
	Embed(godishook.NewEmbed().
		Title("Preview").
		Image("attachment://photo.png")).
	File(godishook.FileFromBytes("photo.png", pngBytes)))

Forum / media threads

client.Send(ctx, godishook.Message().
	Content("New post").
	ThreadName("Release notes").
	AppliedTags("1234567890"))

Or post into an existing thread:

client.Send(ctx, godishook.Message().
	Content("Reply").
	ThreadID("836856309672348295"))

Polls

client.Send(ctx, godishook.Message().
	Poll(godishook.NewPoll("Ship Friday?").
		Answer("Yes").
		Answer("No").
		DurationHours(24)))

Components

Non-application-owned webhooks need EnableComponents(true) (sets with_components=true):

client.Send(ctx, godishook.Message().
	Content("Choose").
	EnableComponents(true).
	Component(godishook.NewActionRow(
		godishook.NewButton(godishook.ButtonPrimary, "Approve", "approve"),
		godishook.NewLinkButton("Docs", "https://example.com"),
	)))

Components V2 (text display / containers) requires the IS_COMPONENTS_V2 flag and cannot mix with content / embeds / poll:

client.Send(ctx, godishook.Message().
	ComponentsV2().
	EnableComponents(true).
	Component(
		godishook.NewContainer(
			godishook.NewTextDisplay("**Status:** healthy"),
			godishook.NewSeparator(godishook.SeparatorSmall, true),
		).WithAccentColor(0x5865F2),
	))

Edit / delete

client.EditMessage(ctx, msg.ID, godishook.EditMessage().Content("Updated"), nil)
client.DeleteMessage(ctx, msg.ID, nil)

Mentions

godishook.Message().
	Content("Hello <@123>").
	AllowedMentions(godishook.Mentions().None())

Options

client, err := godishook.New(id, token,
	godishook.WithHTTPClient(customClient),
	godishook.WithBaseURL("https://discord.com/api/v10"),
	godishook.WithUserAgent("my-app/1.0"),
)

Errors

Failed Discord responses return *godishook.APIError with status, Discord code, message, raw body, and optional RetryAfter (no automatic retries).

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseWebhookURL

func ParseWebhookURL(webhookURL string) (id, token string, err error)

ParseWebhookURL extracts id and token from a Discord webhook URL.

Types

type APIError

type APIError struct {
	StatusCode  int
	Code        int
	Message     string
	RawBody     []byte
	RetryAfter  float64
	RateLimited bool
	Errors      json.RawMessage
}

APIError is a non-success Discord API response.

func (*APIError) Error

func (e *APIError) Error() string

type ActionRow

type ActionRow struct {
	Type       ComponentType `json:"type"`
	ID         int           `json:"id,omitempty"`
	Components []Component   `json:"components"`
}

ActionRow holds up to 5 buttons or a single select menu.

func NewActionRow

func NewActionRow(children ...Component) *ActionRow

NewActionRow creates an action row with the given child components.

type AllowedMentions

type AllowedMentions struct {
	Parse       []MentionType `json:"parse,omitempty"`
	Roles       []string      `json:"roles,omitempty"`
	Users       []string      `json:"users,omitempty"`
	RepliedUser *bool         `json:"replied_user,omitempty"`
	// contains filtered or unexported fields
}

AllowedMentions controls which mentions notify users.

func Mentions

func Mentions() *AllowedMentions

Mentions starts a fluent allowed-mentions builder.

func (*AllowedMentions) All

func (m *AllowedMentions) All() *AllowedMentions

All allows parsing roles, users, and everyone mentions.

func (AllowedMentions) MarshalJSON

func (m AllowedMentions) MarshalJSON() ([]byte, error)

MarshalJSON ensures None() serializes as "parse":[].

func (*AllowedMentions) None

func (m *AllowedMentions) None() *AllowedMentions

None disables all parsed mentions.

func (*AllowedMentions) ParseTypes

func (m *AllowedMentions) ParseTypes(types ...MentionType) *AllowedMentions

ParseTypes sets which mention types may be parsed from content.

func (*AllowedMentions) ReplyMention

func (m *AllowedMentions) ReplyMention(mention bool) *AllowedMentions

ReplyMention sets whether the replied-to user is mentioned.

func (*AllowedMentions) RoleIDs

func (m *AllowedMentions) RoleIDs(ids ...string) *AllowedMentions

RoleIDs restricts role mentions to the given IDs.

func (*AllowedMentions) UserIDs

func (m *AllowedMentions) UserIDs(ids ...string) *AllowedMentions

UserIDs restricts user mentions to the given IDs.

type Attachment

type Attachment struct {
	ID          string `json:"id"`
	Filename    string `json:"filename"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	ContentType string `json:"content_type,omitempty"`
	Size        int    `json:"size"`
	URL         string `json:"url"`
	ProxyURL    string `json:"proxy_url"`
	Height      *int   `json:"height,omitempty"`
	Width       *int   `json:"width,omitempty"`
	Ephemeral   bool   `json:"ephemeral,omitempty"`
	Flags       int    `json:"flags,omitempty"`
}

Attachment is a received attachment object.

type AttachmentRef

type AttachmentRef struct {
	ID          any    `json:"id"`
	Filename    string `json:"filename,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	IsSpoiler   *bool  `json:"is_spoiler,omitempty"`
}

AttachmentRef is attachment metadata sent in the JSON payload.

type Button

type Button struct {
	Type     ComponentType   `json:"type"`
	ID       int             `json:"id,omitempty"`
	Style    ButtonStyle     `json:"style"`
	Label    string          `json:"label,omitempty"`
	Emoji    *ComponentEmoji `json:"emoji,omitempty"`
	CustomID string          `json:"custom_id,omitempty"`
	SKUId    string          `json:"sku_id,omitempty"`
	URL      string          `json:"url,omitempty"`
	Disabled bool            `json:"disabled,omitempty"`
}

Button is an interactive button.

func NewButton

func NewButton(style ButtonStyle, label, customID string) *Button

NewButton creates a non-link button.

func NewLinkButton

func NewLinkButton(label, url string) *Button

NewLinkButton creates a link-style button.

func (*Button) SetDisabled

func (b *Button) SetDisabled(disabled bool) *Button

SetDisabled disables the button.

func (*Button) WithEmoji

func (b *Button) WithEmoji(name, id string, animated bool) *Button

WithEmoji sets a button emoji.

type ButtonStyle

type ButtonStyle int

ButtonStyle is a Discord button style.

const (
	ButtonPrimary   ButtonStyle = 1
	ButtonSecondary ButtonStyle = 2
	ButtonSuccess   ButtonStyle = 3
	ButtonDanger    ButtonStyle = 4
	ButtonLink      ButtonStyle = 5
	ButtonPremium   ButtonStyle = 6
)

type ChannelSelect

type ChannelSelect struct {
	Type          ComponentType        `json:"type"`
	ID            int                  `json:"id,omitempty"`
	CustomID      string               `json:"custom_id"`
	ChannelTypes  []int                `json:"channel_types,omitempty"`
	Placeholder   string               `json:"placeholder,omitempty"`
	DefaultValues []SelectDefaultValue `json:"default_values,omitempty"`
	MinValues     *int                 `json:"min_values,omitempty"`
	MaxValues     *int                 `json:"max_values,omitempty"`
	Disabled      bool                 `json:"disabled,omitempty"`
}

ChannelSelect is a channel select menu.

func NewChannelSelect

func NewChannelSelect(customID string) *ChannelSelect

NewChannelSelect creates a channel select menu.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client sends Discord webhook requests using a webhook id and token.

func New

func New(id, token string, opts ...Option) (*Client, error)

New creates a client from webhook id and token.

func NewFromURL

func NewFromURL(webhookURL string, opts ...Option) (*Client, error)

NewFromURL creates a client by parsing a Discord webhook URL. Accepts forms like:

https://discord.com/api/webhooks/{id}/{token}
https://discord.com/api/v10/webhooks/{id}/{token}

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(ctx context.Context, messageID string, opts *MessageOpts) error

DeleteMessage deletes a previously sent webhook message.

func (*Client) EditMessage

func (c *Client) EditMessage(ctx context.Context, messageID string, in any, opts *EditOpts) (*WebhookMessage, error)

EditMessage edits a previously sent webhook message. in may be *Payload or PayloadBuilder; username/avatar overrides are ignored.

func (*Client) GetMessage

func (c *Client) GetMessage(ctx context.Context, messageID string, opts *MessageOpts) (*WebhookMessage, error)

GetMessage fetches a previously sent webhook message.

func (*Client) ID

func (c *Client) ID() string

ID returns the webhook id.

func (*Client) Send

func (c *Client) Send(ctx context.Context, in any) (*WebhookMessage, error)

Send executes the webhook with the given payload (*Payload or builder). When wait is true (default for Message()), the created message is returned. When wait is false, the returned message is nil on success.

func (*Client) SendSlack

func (c *Client) SendSlack(ctx context.Context, body any) error

SendSlack sends a Slack-compatible payload to the webhook.

func (*Client) URL

func (c *Client) URL() string

URL returns the execute webhook URL (without query).

type Component

type Component interface {
	// contains filtered or unexported methods
}

Component is any Discord message component. Concrete types below marshal to JSON.

type ComponentEmoji

type ComponentEmoji struct {
	ID       string `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	Animated bool   `json:"animated,omitempty"`
}

ComponentEmoji is a partial emoji on components.

type ComponentType

type ComponentType int

ComponentType identifies a Discord message component.

const (
	ComponentActionRow         ComponentType = 1
	ComponentButton            ComponentType = 2
	ComponentStringSelect      ComponentType = 3
	ComponentTextInput         ComponentType = 4
	ComponentUserSelect        ComponentType = 5
	ComponentRoleSelect        ComponentType = 6
	ComponentMentionableSelect ComponentType = 7
	ComponentChannelSelect     ComponentType = 8
	ComponentSection           ComponentType = 9
	ComponentTextDisplay       ComponentType = 10
	ComponentThumbnail         ComponentType = 11
	ComponentMediaGallery      ComponentType = 12
	ComponentFile              ComponentType = 13
	ComponentSeparator         ComponentType = 14
	ComponentContainer         ComponentType = 17
	ComponentLabel             ComponentType = 18
)

type Container

type Container struct {
	Type        ComponentType `json:"type"`
	ID          int           `json:"id,omitempty"`
	Components  []Component   `json:"components"`
	AccentColor *int          `json:"accent_color,omitempty"`
	Spoiler     bool          `json:"spoiler,omitempty"`
}

Container visually groups Components V2 children.

func NewContainer

func NewContainer(children ...Component) *Container

NewContainer creates a container of child components.

func (*Container) WithAccentColor

func (c *Container) WithAccentColor(color int) *Container

WithAccentColor sets the container accent color.

type EditOpts

type EditOpts struct {
	ThreadID       string
	WithComponents *bool
}

EditOpts are optional query params for edit message.

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       *int         `json:"color,omitempty"`
	Footer      *EmbedFooter `json:"footer,omitempty"`
	Image       *EmbedMedia  `json:"image,omitempty"`
	Thumbnail   *EmbedMedia  `json:"thumbnail,omitempty"`
	Author      *EmbedAuthor `json:"author,omitempty"`
	Fields      []EmbedField `json:"fields,omitempty"`
}

Embed is a Discord rich embed.

type EmbedAuthor

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

EmbedAuthor is an embed author block.

type EmbedBuilder

type EmbedBuilder struct {
	// contains filtered or unexported fields
}

EmbedBuilder is a fluent builder for Embed.

func NewEmbed

func NewEmbed() *EmbedBuilder

NewEmbed starts a fluent embed builder.

func (*EmbedBuilder) AddFields

func (b *EmbedBuilder) AddFields(fields ...EmbedField) *EmbedBuilder

AddFields appends multiple embed fields.

func (*EmbedBuilder) Author

func (b *EmbedBuilder) Author(name, url, iconURL string) *EmbedBuilder

Author sets the embed author.

func (*EmbedBuilder) Build

func (b *EmbedBuilder) Build() *Embed

Build returns the constructed Embed.

func (*EmbedBuilder) Color

func (b *EmbedBuilder) Color(color int) *EmbedBuilder

Color sets the embed sidebar color (0xRRGGBB).

func (*EmbedBuilder) Description

func (b *EmbedBuilder) Description(description string) *EmbedBuilder

Description sets the embed description.

func (*EmbedBuilder) Field

func (b *EmbedBuilder) Field(name, value string, inline bool) *EmbedBuilder

Field appends an embed field.

func (*EmbedBuilder) Footer

func (b *EmbedBuilder) Footer(text, iconURL string) *EmbedBuilder

Footer sets footer text and optional icon URL.

func (*EmbedBuilder) Image

func (b *EmbedBuilder) Image(url string) *EmbedBuilder

Image sets the embed image URL (http(s) or attachment://).

func (*EmbedBuilder) Thumbnail

func (b *EmbedBuilder) Thumbnail(url string) *EmbedBuilder

Thumbnail sets the embed thumbnail URL.

func (*EmbedBuilder) Timestamp

func (b *EmbedBuilder) Timestamp(t time.Time) *EmbedBuilder

Timestamp sets the embed timestamp (RFC3339).

func (*EmbedBuilder) TimestampString

func (b *EmbedBuilder) TimestampString(ts string) *EmbedBuilder

TimestampString sets the embed timestamp from a raw string.

func (*EmbedBuilder) Title

func (b *EmbedBuilder) Title(title string) *EmbedBuilder

Title sets the embed title.

func (*EmbedBuilder) URL

func (b *EmbedBuilder) URL(url string) *EmbedBuilder

URL sets the embed URL.

type EmbedField

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

EmbedField is a single embed field.

type EmbedFooter

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

EmbedFooter is an embed footer.

type EmbedMedia

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

EmbedMedia is an embed image or thumbnail.

type File

type File struct {
	Name        string
	Reader      io.Reader
	ContentType string
	Description string
	Title       string
	Spoiler     bool
	// contains filtered or unexported fields
}

File is a file attachment to upload with a webhook message.

func FileFromBytes

func FileFromBytes(name string, data []byte) *File

FileFromBytes creates a file from a byte slice.

func FileFromPath

func FileFromPath(path string) (*File, error)

FileFromPath opens a local file for upload. The caller does not need to close it; encoding reads it during the request.

func FileFromReader

func FileFromReader(name string, r io.Reader) *File

FileFromReader creates a file from an io.Reader.

func (*File) AsSpoiler

func (f *File) AsSpoiler() *File

AsSpoiler marks the attachment as a spoiler.

func (*File) WithContentType

func (f *File) WithContentType(ct string) *File

WithContentType sets the MIME type.

func (*File) WithDescription

func (f *File) WithDescription(desc string) *File

WithDescription sets alt-text description metadata.

func (*File) WithTitle

func (f *File) WithTitle(title string) *File

WithTitle sets the attachment title.

type FileComponent

type FileComponent struct {
	Type    ComponentType     `json:"type"`
	ID      int               `json:"id,omitempty"`
	File    UnfurledMediaItem `json:"file"`
	Spoiler bool              `json:"spoiler,omitempty"`
}

FileComponent displays an attached file (Components V2).

func NewFileComponent

func NewFileComponent(attachmentURL string) *FileComponent

NewFileComponent creates a file display component (attachment:// only).

type MediaGallery

type MediaGallery struct {
	Type  ComponentType      `json:"type"`
	ID    int                `json:"id,omitempty"`
	Items []MediaGalleryItem `json:"items"`
}

MediaGallery displays a gallery of media.

func NewMediaGallery

func NewMediaGallery(items ...MediaGalleryItem) *MediaGallery

NewMediaGallery creates a media gallery.

type MediaGalleryItem

type MediaGalleryItem struct {
	Media       UnfurledMediaItem `json:"media"`
	Description string            `json:"description,omitempty"`
	Spoiler     bool              `json:"spoiler,omitempty"`
}

MediaGalleryItem is one item in a media gallery.

type MentionType

type MentionType string

MentionType is an allowed mention parse type.

const (
	MentionRoles    MentionType = "roles"
	MentionUsers    MentionType = "users"
	MentionEveryone MentionType = "everyone"
)

type MentionableSelect

type MentionableSelect struct {
	Type          ComponentType        `json:"type"`
	ID            int                  `json:"id,omitempty"`
	CustomID      string               `json:"custom_id"`
	Placeholder   string               `json:"placeholder,omitempty"`
	DefaultValues []SelectDefaultValue `json:"default_values,omitempty"`
	MinValues     *int                 `json:"min_values,omitempty"`
	MaxValues     *int                 `json:"max_values,omitempty"`
	Disabled      bool                 `json:"disabled,omitempty"`
}

MentionableSelect is a mentionable (user+role) select menu.

func NewMentionableSelect

func NewMentionableSelect(customID string) *MentionableSelect

NewMentionableSelect creates a mentionable select menu.

type MessageBuilder

type MessageBuilder struct {
	// contains filtered or unexported fields
}

MessageBuilder is a fluent builder for webhook payloads.

func EditMessage

func EditMessage() *MessageBuilder

EditMessage starts a payload intended for editing an existing webhook message.

func Message

func Message() *MessageBuilder

Message starts a fluent message/payload builder (wait defaults to true).

func (*MessageBuilder) AddFlags

func (b *MessageBuilder) AddFlags(flags MessageFlags) *MessageBuilder

AddFlags ORs additional flags onto the payload.

func (*MessageBuilder) AllowedMentions

func (b *MessageBuilder) AllowedMentions(m *AllowedMentions) *MessageBuilder

AllowedMentions sets mention controls.

func (*MessageBuilder) AppliedTags

func (b *MessageBuilder) AppliedTags(tagIDs ...string) *MessageBuilder

AppliedTags sets forum tag IDs for a newly created thread.

func (*MessageBuilder) AttachmentMeta

func (b *MessageBuilder) AttachmentMeta(refs ...AttachmentRef) *MessageBuilder

AttachmentMeta sets/replaces attachment metadata (used heavily on edits).

func (*MessageBuilder) AvatarURL

func (b *MessageBuilder) AvatarURL(url string) *MessageBuilder

AvatarURL overrides the webhook avatar for this message.

func (*MessageBuilder) Build

func (b *MessageBuilder) Build() (*Payload, error)

Build implements PayloadBuilder.

func (*MessageBuilder) Component

func (b *MessageBuilder) Component(components ...Component) *MessageBuilder

Component appends message components.

func (*MessageBuilder) ComponentsV2

func (b *MessageBuilder) ComponentsV2() *MessageBuilder

ComponentsV2 sets the IS_COMPONENTS_V2 flag.

func (*MessageBuilder) Content

func (b *MessageBuilder) Content(content string) *MessageBuilder

Content sets message content (up to 2000 characters).

func (*MessageBuilder) Embed

func (b *MessageBuilder) Embed(embeds ...any) *MessageBuilder

Embed appends embeds (max 10). Accepts *Embed or *EmbedBuilder.

func (*MessageBuilder) EnableComponents

func (b *MessageBuilder) EnableComponents(enable bool) *MessageBuilder

EnableComponents sets with_components=true so non-app webhooks can send components.

func (*MessageBuilder) File

func (b *MessageBuilder) File(files ...*File) *MessageBuilder

File appends file attachments.

func (*MessageBuilder) Poll

func (b *MessageBuilder) Poll(poll any) *MessageBuilder

Poll attaches a poll. Accepts *Poll or *PollBuilder.

func (*MessageBuilder) SetFlags

func (b *MessageBuilder) SetFlags(flags MessageFlags) *MessageBuilder

SetFlags sets message flags.

func (*MessageBuilder) SuppressEmbeds

func (b *MessageBuilder) SuppressEmbeds() *MessageBuilder

SuppressEmbeds sets the SUPPRESS_EMBEDS flag.

func (*MessageBuilder) SuppressNotifications

func (b *MessageBuilder) SuppressNotifications() *MessageBuilder

SuppressNotifications sets the SUPPRESS_NOTIFICATIONS flag.

func (*MessageBuilder) TTS

func (b *MessageBuilder) TTS(tts bool) *MessageBuilder

TTS marks the message as text-to-speech.

func (*MessageBuilder) ThreadID

func (b *MessageBuilder) ThreadID(id string) *MessageBuilder

ThreadID targets an existing thread in the webhook channel.

func (*MessageBuilder) ThreadName

func (b *MessageBuilder) ThreadName(name string) *MessageBuilder

ThreadName creates a forum/media thread with this name.

func (*MessageBuilder) Username

func (b *MessageBuilder) Username(username string) *MessageBuilder

Username overrides the webhook username for this message.

func (*MessageBuilder) Wait

func (b *MessageBuilder) Wait(wait bool) *MessageBuilder

Wait controls whether Discord returns the created message body.

type MessageFlags

type MessageFlags int

MessageFlags are Discord message flags that can be set on webhook messages.

const (
	// FlagSuppressEmbeds suppresses embeds from being shown.
	FlagSuppressEmbeds MessageFlags = 1 << 2
	// FlagSuppressNotifications suppresses push and desktop notifications.
	FlagSuppressNotifications MessageFlags = 1 << 12
	// FlagIsComponentsV2 enables the Components V2 layout (content/embeds/poll disabled).
	FlagIsComponentsV2 MessageFlags = 1 << 15
)

type MessageOpts

type MessageOpts struct {
	ThreadID string
}

MessageOpts are optional query params for get/delete message.

type Option

type Option func(*Client)

Option configures a Client.

func WithBaseURL

func WithBaseURL(base string) Option

WithBaseURL overrides the API base URL (default https://discord.com/api/v10).

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent sets the User-Agent header.

type Payload

type Payload struct {
	Content         string           `json:"content,omitempty"`
	Username        string           `json:"username,omitempty"`
	AvatarURL       string           `json:"avatar_url,omitempty"`
	TTS             bool             `json:"tts,omitempty"`
	Embeds          []*Embed         `json:"embeds,omitempty"`
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
	Components      []Component      `json:"components,omitempty"`
	Attachments     []AttachmentRef  `json:"attachments,omitempty"`
	Flags           MessageFlags     `json:"flags,omitempty"`
	ThreadName      string           `json:"thread_name,omitempty"`
	AppliedTags     []string         `json:"applied_tags,omitempty"`
	Poll            *Poll            `json:"poll,omitempty"`

	// Files are uploaded via multipart/form-data (not serialized as JSON).
	Files []*File `json:"-"`

	// Query string options (not part of the JSON body).
	Wait           *bool  `json:"-"`
	ThreadID       string `json:"-"`
	WithComponents *bool  `json:"-"`
	// contains filtered or unexported fields
}

Payload is a Discord Execute Webhook / Edit Webhook Message body plus query options.

type PayloadBuilder

type PayloadBuilder interface {
	Build() (*Payload, error)
}

PayloadBuilder builds a Payload.

type Poll

type Poll struct {
	Question         PollMedia      `json:"question"`
	Answers          []PollAnswer   `json:"answers"`
	Duration         *int           `json:"duration,omitempty"`
	AllowMultiselect *bool          `json:"allow_multiselect,omitempty"`
	LayoutType       PollLayoutType `json:"layout_type,omitempty"`
}

Poll is a poll create request.

type PollAnswer

type PollAnswer struct {
	PollMedia PollMedia `json:"poll_media"`
}

PollAnswer is a single poll answer.

type PollBuilder

type PollBuilder struct {
	// contains filtered or unexported fields
}

PollBuilder is a fluent builder for Poll.

func NewPoll

func NewPoll(question string) *PollBuilder

NewPoll starts a fluent poll builder with a question.

func (*PollBuilder) Answer

func (b *PollBuilder) Answer(text string) *PollBuilder

Answer adds a text answer.

func (*PollBuilder) AnswerWithEmoji

func (b *PollBuilder) AnswerWithEmoji(text, emojiID, emojiName string) *PollBuilder

AnswerWithEmoji adds a text answer with an emoji (custom id or unicode name).

func (*PollBuilder) Build

func (b *PollBuilder) Build() *Poll

Build returns the constructed Poll.

func (*PollBuilder) DurationHours

func (b *PollBuilder) DurationHours(hours int) *PollBuilder

DurationHours sets how long the poll stays open (hours, max 32 days).

func (*PollBuilder) Layout

func (b *PollBuilder) Layout(layout PollLayoutType) *PollBuilder

Layout sets the poll layout type.

func (*PollBuilder) Multiselect

func (b *PollBuilder) Multiselect(allow bool) *PollBuilder

Multiselect allows selecting multiple answers.

type PollEmoji

type PollEmoji struct {
	ID       string `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	Animated bool   `json:"animated,omitempty"`
}

PollEmoji is a partial emoji for poll answers.

type PollLayoutType

type PollLayoutType int

PollLayoutType is a Discord poll layout.

const (
	PollLayoutDefault PollLayoutType = 1
)

type PollMedia

type PollMedia struct {
	Text  string     `json:"text,omitempty"`
	Emoji *PollEmoji `json:"emoji,omitempty"`
}

PollMedia is question/answer media.

type RawComponent

type RawComponent struct {
	JSON json.RawMessage
}

RawComponent is an escape hatch for unsupported or custom component JSON.

func (RawComponent) MarshalJSON

func (r RawComponent) MarshalJSON() ([]byte, error)

type RoleSelect

type RoleSelect struct {
	Type          ComponentType        `json:"type"`
	ID            int                  `json:"id,omitempty"`
	CustomID      string               `json:"custom_id"`
	Placeholder   string               `json:"placeholder,omitempty"`
	DefaultValues []SelectDefaultValue `json:"default_values,omitempty"`
	MinValues     *int                 `json:"min_values,omitempty"`
	MaxValues     *int                 `json:"max_values,omitempty"`
	Disabled      bool                 `json:"disabled,omitempty"`
}

RoleSelect is a role select menu.

func NewRoleSelect

func NewRoleSelect(customID string) *RoleSelect

NewRoleSelect creates a role select menu.

type Section

type Section struct {
	Type       ComponentType `json:"type"`
	ID         int           `json:"id,omitempty"`
	Components []Component   `json:"components"`
	Accessory  Component     `json:"accessory"`
}

Section groups text displays with an accessory (button or thumbnail).

func NewSection

func NewSection(accessory Component, text ...*TextDisplay) *Section

NewSection creates a section with text children and an accessory.

type SelectDefaultValue

type SelectDefaultValue struct {
	ID   string `json:"id"`
	Type string `json:"type"` // "user", "role", or "channel"
}

SelectDefaultValue is a default value for entity selects.

type SelectOption

type SelectOption struct {
	Label       string          `json:"label"`
	Value       string          `json:"value"`
	Description string          `json:"description,omitempty"`
	Emoji       *ComponentEmoji `json:"emoji,omitempty"`
	Default     bool            `json:"default,omitempty"`
}

SelectOption is a string select option.

type Separator

type Separator struct {
	Type    ComponentType    `json:"type"`
	ID      int              `json:"id,omitempty"`
	Divider *bool            `json:"divider,omitempty"`
	Spacing SeparatorSpacing `json:"spacing,omitempty"`
}

Separator adds vertical padding between Components V2 blocks.

func NewSeparator

func NewSeparator(spacing SeparatorSpacing, divider bool) *Separator

NewSeparator creates a separator.

type SeparatorSpacing

type SeparatorSpacing int

SeparatorSpacing is Components V2 separator spacing.

const (
	SeparatorSmall SeparatorSpacing = 1
	SeparatorLarge SeparatorSpacing = 2
)

type StringSelect

type StringSelect struct {
	Type        ComponentType  `json:"type"`
	ID          int            `json:"id,omitempty"`
	CustomID    string         `json:"custom_id"`
	Options     []SelectOption `json:"options"`
	Placeholder string         `json:"placeholder,omitempty"`
	MinValues   *int           `json:"min_values,omitempty"`
	MaxValues   *int           `json:"max_values,omitempty"`
	Disabled    bool           `json:"disabled,omitempty"`
}

StringSelect is a string select menu.

func NewStringSelect

func NewStringSelect(customID string, options ...SelectOption) *StringSelect

NewStringSelect creates a string select menu.

type TextDisplay

type TextDisplay struct {
	Type    ComponentType `json:"type"`
	ID      int           `json:"id,omitempty"`
	Content string        `json:"content"`
}

TextDisplay is a Components V2 markdown text block.

func NewTextDisplay

func NewTextDisplay(content string) *TextDisplay

NewTextDisplay creates a text display component.

type Thumbnail

type Thumbnail struct {
	Type        ComponentType     `json:"type"`
	ID          int               `json:"id,omitempty"`
	Media       UnfurledMediaItem `json:"media"`
	Description string            `json:"description,omitempty"`
	Spoiler     bool              `json:"spoiler,omitempty"`
}

Thumbnail is a small image accessory.

func NewThumbnail

func NewThumbnail(url string) *Thumbnail

NewThumbnail creates a thumbnail from a URL or attachment:// reference.

type UnfurledMediaItem

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

UnfurledMediaItem is media referenced by Components V2.

type User

type User struct {
	ID            string `json:"id"`
	Username      string `json:"username"`
	Discriminator string `json:"discriminator"`
	GlobalName    string `json:"global_name,omitempty"`
	Avatar        string `json:"avatar,omitempty"`
	Bot           bool   `json:"bot,omitempty"`
}

User is a partial Discord user (webhook author).

type UserSelect

type UserSelect struct {
	Type          ComponentType        `json:"type"`
	ID            int                  `json:"id,omitempty"`
	CustomID      string               `json:"custom_id"`
	Placeholder   string               `json:"placeholder,omitempty"`
	DefaultValues []SelectDefaultValue `json:"default_values,omitempty"`
	MinValues     *int                 `json:"min_values,omitempty"`
	MaxValues     *int                 `json:"max_values,omitempty"`
	Disabled      bool                 `json:"disabled,omitempty"`
}

UserSelect is a user select menu.

func NewUserSelect

func NewUserSelect(customID string) *UserSelect

NewUserSelect creates a user select menu.

type WebhookMessage

type WebhookMessage struct {
	ID              string         `json:"id"`
	ChannelID       string         `json:"channel_id"`
	Content         string         `json:"content"`
	Timestamp       string         `json:"timestamp"`
	EditedTimestamp string         `json:"edited_timestamp"`
	TTS             bool           `json:"tts"`
	MentionEveryone bool           `json:"mention_everyone"`
	Flags           MessageFlags   `json:"flags"`
	Embeds          []Embed        `json:"embeds"`
	Attachments     []Attachment   `json:"attachments"`
	Components      jsonComponents `json:"components"`
	WebhookID       string         `json:"webhook_id"`
	Author          *User          `json:"author"`
	Type            int            `json:"type"`
	Pinned          bool           `json:"pinned"`
}

WebhookMessage is a Discord message returned when wait=true or fetching/editing.

Directories

Path Synopsis
examples
basic command

Jump to

Keyboard shortcuts

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