Documentation
¶
Index ¶
- func ParseWebhookURL(webhookURL string) (id, token string, err error)
- type APIError
- type ActionRow
- type AllowedMentions
- func (m *AllowedMentions) All() *AllowedMentions
- func (m AllowedMentions) MarshalJSON() ([]byte, error)
- func (m *AllowedMentions) None() *AllowedMentions
- func (m *AllowedMentions) ParseTypes(types ...MentionType) *AllowedMentions
- func (m *AllowedMentions) ReplyMention(mention bool) *AllowedMentions
- func (m *AllowedMentions) RoleIDs(ids ...string) *AllowedMentions
- func (m *AllowedMentions) UserIDs(ids ...string) *AllowedMentions
- type Attachment
- type AttachmentRef
- type Button
- type ButtonStyle
- type ChannelSelect
- type Client
- func (c *Client) DeleteMessage(ctx context.Context, messageID string, opts *MessageOpts) error
- func (c *Client) EditMessage(ctx context.Context, messageID string, in any, opts *EditOpts) (*WebhookMessage, error)
- func (c *Client) GetMessage(ctx context.Context, messageID string, opts *MessageOpts) (*WebhookMessage, error)
- func (c *Client) ID() string
- func (c *Client) Send(ctx context.Context, in any) (*WebhookMessage, error)
- func (c *Client) SendSlack(ctx context.Context, body any) error
- func (c *Client) URL() string
- type Component
- type ComponentEmoji
- type ComponentType
- type Container
- type EditOpts
- type Embed
- type EmbedAuthor
- type EmbedBuilder
- func (b *EmbedBuilder) AddFields(fields ...EmbedField) *EmbedBuilder
- func (b *EmbedBuilder) Author(name, url, iconURL string) *EmbedBuilder
- func (b *EmbedBuilder) Build() *Embed
- func (b *EmbedBuilder) Color(color int) *EmbedBuilder
- func (b *EmbedBuilder) Description(description string) *EmbedBuilder
- func (b *EmbedBuilder) Field(name, value string, inline bool) *EmbedBuilder
- func (b *EmbedBuilder) Footer(text, iconURL string) *EmbedBuilder
- func (b *EmbedBuilder) Image(url string) *EmbedBuilder
- func (b *EmbedBuilder) Thumbnail(url string) *EmbedBuilder
- func (b *EmbedBuilder) Timestamp(t time.Time) *EmbedBuilder
- func (b *EmbedBuilder) TimestampString(ts string) *EmbedBuilder
- func (b *EmbedBuilder) Title(title string) *EmbedBuilder
- func (b *EmbedBuilder) URL(url string) *EmbedBuilder
- type EmbedField
- type EmbedFooter
- type EmbedMedia
- type File
- type FileComponent
- type MediaGallery
- type MediaGalleryItem
- type MentionType
- type MentionableSelect
- type MessageBuilder
- func (b *MessageBuilder) AddFlags(flags MessageFlags) *MessageBuilder
- func (b *MessageBuilder) AllowedMentions(m *AllowedMentions) *MessageBuilder
- func (b *MessageBuilder) AppliedTags(tagIDs ...string) *MessageBuilder
- func (b *MessageBuilder) AttachmentMeta(refs ...AttachmentRef) *MessageBuilder
- func (b *MessageBuilder) AvatarURL(url string) *MessageBuilder
- func (b *MessageBuilder) Build() (*Payload, error)
- func (b *MessageBuilder) Component(components ...Component) *MessageBuilder
- func (b *MessageBuilder) ComponentsV2() *MessageBuilder
- func (b *MessageBuilder) Content(content string) *MessageBuilder
- func (b *MessageBuilder) Embed(embeds ...any) *MessageBuilder
- func (b *MessageBuilder) EnableComponents(enable bool) *MessageBuilder
- func (b *MessageBuilder) File(files ...*File) *MessageBuilder
- func (b *MessageBuilder) Poll(poll any) *MessageBuilder
- func (b *MessageBuilder) SetFlags(flags MessageFlags) *MessageBuilder
- func (b *MessageBuilder) SuppressEmbeds() *MessageBuilder
- func (b *MessageBuilder) SuppressNotifications() *MessageBuilder
- func (b *MessageBuilder) TTS(tts bool) *MessageBuilder
- func (b *MessageBuilder) ThreadID(id string) *MessageBuilder
- func (b *MessageBuilder) ThreadName(name string) *MessageBuilder
- func (b *MessageBuilder) Username(username string) *MessageBuilder
- func (b *MessageBuilder) Wait(wait bool) *MessageBuilder
- type MessageFlags
- type MessageOpts
- type Option
- type Payload
- type PayloadBuilder
- type Poll
- type PollAnswer
- type PollBuilder
- func (b *PollBuilder) Answer(text string) *PollBuilder
- func (b *PollBuilder) AnswerWithEmoji(text, emojiID, emojiName string) *PollBuilder
- func (b *PollBuilder) Build() *Poll
- func (b *PollBuilder) DurationHours(hours int) *PollBuilder
- func (b *PollBuilder) Layout(layout PollLayoutType) *PollBuilder
- func (b *PollBuilder) Multiselect(allow bool) *PollBuilder
- type PollEmoji
- type PollLayoutType
- type PollMedia
- type RawComponent
- type RoleSelect
- type Section
- type SelectDefaultValue
- type SelectOption
- type Separator
- type SeparatorSpacing
- type StringSelect
- type TextDisplay
- type Thumbnail
- type UnfurledMediaItem
- type User
- type UserSelect
- type WebhookMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseWebhookURL ¶
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.
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 ¶
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 (*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 ¶
NewLinkButton creates a link-style button.
func (*Button) SetDisabled ¶
SetDisabled disables the button.
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 NewFromURL ¶
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 ¶
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) Send ¶
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.
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 ¶
NewContainer creates a container of child components.
func (*Container) WithAccentColor ¶
WithAccentColor sets the container accent color.
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"`
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 (*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 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 ¶
FileFromBytes creates a file from a byte slice.
func FileFromPath ¶
FileFromPath opens a local file for upload. The caller does not need to close it; encoding reads it during the request.
func FileFromReader ¶
FileFromReader creates a file from an io.Reader.
func (*File) WithContentType ¶
WithContentType sets the MIME type.
func (*File) WithDescription ¶
WithDescription sets alt-text description metadata.
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 ¶
WithBaseURL overrides the API base URL (default https://discord.com/api/v10).
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
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 ¶
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) 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 ¶
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.