tempest

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: BSD-3-Clause Imports: 16 Imported by: 4

README

Go Reference Go Report Go Version License Maintenance Status CodeQL Conventional Commits

Tempest library logo

Tempest

Tempest is a Discord API wrapper for Applications, written in Golang. It aims to be fast, use minimal caching and be easier to use than other Discord API wrappers using http.

It was created as a better alternative to discord-interactions-go which is "low level" and outdated.

Summary

  1. HTTP vs Gateway
  2. Special features
  3. Getting Started
  4. Troubleshooting
  5. Contributing
HTTP vs Gateway

TL;DR: you probably should be using libraries like DiscordGo unless you know why you're here.

There are two ways for bots to receive events from Discord. Most API wrappers such as DiscordGo use a WebSocket connection called a "gateway" to receive events, but Tempest receives interaction events over HTTP. Using http hooks lets you scale code more easily & reduce resource usage at cost of greatly reduced number of events you can use. You can easily create bots for roles, minigames, custom messages or admin utils but it'll be very difficult / impossible to create music or moderation bots.

Special features
Getting started
  1. Install with: go get -u github.com/amatsagu/tempest
  2. Check example with few simple commands.

Troubleshooting

For help feel free to open an issue on github. You can also inivite to contact me on discord.

Contributing

All contributions are welcomed. Few rules before making a pull request:

  • Use conventional commits
  • Add link to document for new structs
    • Since v1.1.0, all structs should have links to corresponding discord docs

FOSSA Status

Documentation

Index

Constants

View Source
const (
	DiscordAPIURL    = "https://discord.com/api/v10"
	DiscordCDNURL    = "https://cdn.discordapp.com"
	DiscordEpoch     = 1420070400000 // Discord epoch in milliseconds
	UserAgent        = "DiscordApp https://github.com/Amatsagu/tempest"
	ContentTypeJSON  = "application/json"
	ROOT_PLACEHOLDER = "-"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowedMentions added in v1.1.0

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

https://discord.com/developers/docs/resources/channel#allowed-mentions-object-allowed-mentions-structure

type ButtonStyle

type ButtonStyle uint8

https://discord.com/developers/docs/interactions/message-components#button-object-button-styles

const (
	PRIMARY_BUTTON_STYLE   ButtonStyle = iota + 1 // blurple
	SECONDARY_BUTTON_STYLE                        // grey
	SUCCESS_BUTTON_STYLE                          // green
	DANGER_BUTTON_STYLE                           // red
	LINK_BUTTON_STYLE                             // grey, navigate to URL
)

type ChannelMention added in v1.1.0

type ChannelMention struct {
	ID      Snowflake   `json:"id"`
	Name    string      `json:"name"`
	GuildID Snowflake   `json:"guild_id"`
	Type    ChannelType `json:"type"`
}

https://discord.com/developers/docs/resources/channel#channel-mention-object-channel-mention-structure

type ChannelType

type ChannelType uint8

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

const (
	GUILD_TEXT_CHANNEL_TYPE ChannelType = iota
	DM_CHANNEL_TYPE
	GUILD_VOICE_CHANNEL_TYPE
	GROUP_DM_CHANNEL_TYPE
	GUILD_CATEGORY_CHANNEL_TYPE
	GUILD_ANNOUNCEMENT_CHANNEL_TYPE // Formerly news channel.

	GUILD_ANNOUNCEMENT_THREAD_CHANNEL_TYPE
	GUILD_PUBLIC_THREAD_CHANNEL_TYPE
	GUILD_PRIVATE_THREAD_CHANNEL_TYPE
	GUILD_STAGE_VOICE_CHANNEL_TYPE
	GUILD_DIRECTORY_CHANNEL_TYPE
	GUILD_FORUM_CHANNEL_TYPE
)

func (ChannelType) MarshalJSON

func (ct ChannelType) MarshalJSON() (p []byte, err error)

type Choice

type Choice struct {
	Name              string            `json:"name"`
	NameLocalizations map[string]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
	Value             any               `json:"value"`                        // string, float64 (double or integer) or bool
}

https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-choice-structure

type Client

type Client struct {
	Rest          *RestClient
	ApplicationID Snowflake
	PublicKey     ed25519.PublicKey
	// contains filtered or unexported fields
}

func NewClient added in v1.1.0

func NewClient(options ClientOptions) *Client

func (*Client) AwaitComponent

func (client *Client) AwaitComponent(customIDs []string, timeout time.Duration) (<-chan *ComponentInteraction, func(), error)

Makes client dynamically "listen" incoming component type interactions. When component custom id matches - it'll send back interaction through channel. On timeout (min 2s -> max 15min) - client will send <nil> through channel and automatically call close function.

Warning! Components handled this way will already be acknowledged.

func (*Client) AwaitModal added in v1.1.0

func (client *Client) AwaitModal(customID string, timeout time.Duration) (<-chan *ModalInteraction, func(), error)

Makes client dynamically "listen" incoming modal type interactions. When modal custom id matches - it'll send back interaction through channel. On timeout (min 30s -> max 15min) - client will send <nil> through channel and automatically call close function.

Warning! Components handled this way will already be acknowledged.

func (*Client) CrosspostMessage

func (client *Client) CrosspostMessage(channelID Snowflake, messageID Snowflake) error

func (*Client) DeleteMessage

func (client *Client) DeleteMessage(channelID Snowflake, messageID Snowflake) error

func (*Client) EditMessage

func (client *Client) EditMessage(channelID Snowflake, messageID Snowflake, content Message) error

func (*Client) FetchMember

func (client *Client) FetchMember(guildID Snowflake, memberID Snowflake) (Member, error)

func (*Client) FetchUser

func (client *Client) FetchUser(id Snowflake) (User, error)

func (*Client) HandleDiscordRequest added in v1.2.0

func (client *Client) HandleDiscordRequest(w http.ResponseWriter, r *http.Request)

func (*Client) Ping

func (client *Client) Ping() time.Duration

Pings Discord API and returns time it took to get response.

func (*Client) RegisterCommand

func (client *Client) RegisterCommand(command Command) error

func (*Client) RegisterComponent added in v1.1.0

func (client *Client) RegisterComponent(customIDs []string, fn func(ComponentInteraction)) error

Bind function to all components with matching custom ids. App will automatically run bound function whenever receiving component interaction with matching custom id.

func (*Client) RegisterModal added in v1.1.0

func (client *Client) RegisterModal(customID string, fn func(ModalInteraction)) error

Bind function to modal with matching custom id. App will automatically run bound function whenever receiving modal interaction with matching custom id.

func (*Client) RegisterSubCommand

func (client *Client) RegisterSubCommand(subCommand Command, rootCommandName string) error

func (*Client) SendLinearMessage

func (client *Client) SendLinearMessage(channelID Snowflake, content string) (Message, error)

func (*Client) SendMessage

func (client *Client) SendMessage(channelID Snowflake, message Message, files []*os.File) (Message, error)

func (*Client) SendPrivateMessage added in v1.0.2

func (client *Client) SendPrivateMessage(userID Snowflake, content Message, files []*os.File) (Message, error)

Creates (or fetches if already exists) user's private text channel (DM) and tries to send message into it. Warning! Discord's user channels endpoint has huge rate limits so please reuse Message#ChannelID whenever possible.

func (*Client) SyncCommands

func (client *Client) SyncCommands(guildIDs []Snowflake, whitelist []string, switchMode bool) error

Sync currently cached slash commands to discord API. By default it'll try to make (bulk) global update (limit 100 updates per day), provide array with guild id snowflakes to update data only for specific guilds. You can also add second param -> slice with all command names you want to update (whitelist). There's also third, boolean param that when = true will reverse wishlist to work as blacklist.

type ClientOptions

type ClientOptions struct {
	PublicKey        string // Hash like key used to verify incoming payloads from Discord. (default: <nil>)
	Rest             *RestClient
	PreCommandHook   func(cmd *Command, itx *CommandInteraction) bool // Function that runs before each command. Return type signals whether to continue command execution (return with false to stop early).
	PostCommandHook  func(cmd *Command, itx *CommandInteraction)      // Function that runs after each command.
	ComponentHandler func(itx *ComponentInteraction)                  // Function that runs for each unhandled component.
	ModalHandler     func(itx *ModalInteraction)                      // Function that runs for each unhandled modal.
}

type Command

type Command struct {
	ID                       Snowflake           `json:"-"` // Omit in json parsing for now because it was breaking Client#commandParse.
	Type                     CommandType         `json:"type,omitempty"`
	ApplicationID            Snowflake           `json:"application_id"`
	GuildID                  Snowflake           `json:"guild_id,omitempty"`
	Name                     string              `json:"name"`
	NameLocalizations        map[Language]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
	Description              string              `json:"description"`
	DescriptionLocalizations map[Language]string `json:"description_localizations,omitempty"`
	Options                  []CommandOption     `json:"options,omitempty"`
	DefaultMemberPermissions uint64              `json:"default_member_permissions,string,omitempty"` // Set of permissions represented as a bit set. Set it to 0 to make command unavailable for regular members.
	AvailableInDM            bool                `json:"dm_permission,omitempty"`                     // Whether command should be visible (usable) from private, dm channels. Works only for global commands!
	NSFW                     bool                `json:"nsfw,omitempty"`                              // https://discord.com/developers/docs/interactions/application-commands#agerestricted-commands
	Version                  Snowflake           `json:"version,omitempty"`                           // Autoincrementing version identifier updated during substantial record changes

	AutoCompleteHandler func(itx CommandInteraction) []Choice `json:"-"` // Custom handler for auto complete interactions. It's a Tempest specific field.
	SlashCommandHandler func(itx *CommandInteraction)         `json:"-"` // Custom handler for slash command interactions. It's a Tempest specific field. It receives pointer to CommandInteraction as it's being used with pre & post client hooks.
}

https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure

type CommandInteraction

type CommandInteraction struct {
	ID              Snowflake              `json:"id"`
	ApplicationID   Snowflake              `json:"application_id"`
	Type            InteractionType        `json:"type"`
	Data            CommandInteractionData `json:"data"`
	GuildID         Snowflake              `json:"guild_id,omitempty"`
	ChannelID       Snowflake              `json:"channel_id,omitempty"`
	Member          *Member                `json:"member,omitempty"`
	User            *User                  `json:"user,omitempty"`
	Token           string                 `json:"token"`                  // Temporary token used for responding to the interaction. It's not the same as bot/app token.
	Version         uint8                  `json:"version"`                // Read-only property, always = 1.
	PermissionFlags uint64                 `json:"app_permissions,string"` // Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
	Locale          string                 `json:"locale,omitempty"`       // Selected language of the invoking user.
	GuildLocale     string                 `json:"guild_locale,omitempty"` // Guild's preferred locale, available if invoked in a guild.

	Client *Client `json:"-"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object

func (CommandInteraction) Defer

func (itx CommandInteraction) Defer(ephemeral bool) error

Use to let user/member know that bot is processing command. Make ephemeral = true to make notification visible only to target.

func (CommandInteraction) DeleteFollowUp

func (itx CommandInteraction) DeleteFollowUp(messageID Snowflake, content ResponseMessage) error

func (CommandInteraction) DeleteReply

func (itx CommandInteraction) DeleteReply() error

func (CommandInteraction) EditFollowUp

func (itx CommandInteraction) EditFollowUp(messageID Snowflake, content ResponseMessage) error

func (CommandInteraction) EditReply

func (itx CommandInteraction) EditReply(content ResponseMessageData, ephemeral bool) error

func (CommandInteraction) GetFocusedValue added in v1.1.4

func (itx CommandInteraction) GetFocusedValue() (string, any)

Warning! This method is only for handling auto complete interaction which is a part of command logic. Returns option name and its value of triggered option. Option name is always of string type but you'll need to check type of value.

func (CommandInteraction) GetOptionValue

func (itx CommandInteraction) GetOptionValue(name string) (any, bool)

Returns value of any type. Check second value to check whether option was provided or not (true if yes).

func (CommandInteraction) ResolveMember

func (itx CommandInteraction) ResolveMember(id Snowflake) *Member

Returns pointer to member if present in interaction.data.resolved and binds member.user. It'll return <nil> if there's no resolved member.

func (CommandInteraction) ResolveRole

func (itx CommandInteraction) ResolveRole(id Snowflake) *Role

Returns pointer to guild role if present in interaction.data.resolved. It'll return <nil> if there's no resolved role.

func (CommandInteraction) ResolveUser

func (itx CommandInteraction) ResolveUser(id Snowflake) *User

Returns pointer to user if present in interaction.data.resolved. It'll return <nil> if there's no resolved user.

func (CommandInteraction) SendFollowUp

func (itx CommandInteraction) SendFollowUp(content ResponseMessageData, ephemeral bool) (Message, error)

func (CommandInteraction) SendLinearReply

func (itx CommandInteraction) SendLinearReply(content string, ephemeral bool) error

Use that for simple text messages that won't be modified.

func (CommandInteraction) SendModal added in v1.0.4

func (itx CommandInteraction) SendModal(modal ResponseModalData) error

func (CommandInteraction) SendReply

func (itx CommandInteraction) SendReply(reply ResponseMessageData, ephemeral bool, files []*os.File) error

Acknowledges the interaction with a message. Set ephemeral = true to make message visible only to target.

type CommandInteractionData added in v1.1.0

type CommandInteractionData struct {
	ID       Snowflake                   `json:"id,omitempty"`
	Name     string                      `json:"name"`
	Type     CommandType                 `json:"type"`
	Resolved *InteractionDataResolved    `json:"resolved,omitempty"`
	Options  []*CommandInteractionOption `json:"options,omitempty"`
	GuildID  Snowflake                   `json:"guild_id,omitempty"`
	TargetID Snowflake                   `json:"target_id,omitempty"` // ID of either user or message targeted. Depends whether it was user command or message command.
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-data-structure

type CommandInteractionOption added in v1.1.0

type CommandInteractionOption struct {
	Name    string                      `json:"name"`
	Type    OptionType                  `json:"type"`
	Value   any                         `json:"value,omitempty"` // string, float64 (double or integer) or bool
	Options []*CommandInteractionOption `json:"options,omitempty"`
	Focused bool                        `json:"focused,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-interaction-data-option-structure

type CommandOption added in v1.1.0

type CommandOption struct {
	Type                     OptionType          `json:"type"`
	Name                     string              `json:"name"`
	NameLocalizations        map[Language]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
	Description              string              `json:"description"`
	DescriptionLocalizations map[Language]string `json:"description_localizations,omitempty"`
	Required                 bool                `json:"required,omitempty"`
	MinValue                 float64             `json:"min_value,omitempty"`
	MaxValue                 float64             `json:"max_value,omitempty"`
	MinLength                uint                `json:"min_length,omitempty"`
	MaxLength                uint                `json:"max_length,omitempty"`
	Options                  []CommandOption     `json:"options,omitempty"`
	ChannelTypes             []ChannelType       `json:"channel_types,omitempty"`
	Choices                  []Choice            `json:"choices,omitempty"`
	AutoComplete             bool                `json:"autocomplete,omitempty"` // Required to be = true if you want to catch it later in auto complete handler.
}

https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure

type CommandType

type CommandType uint8

https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types

const (
	CHAT_INPUT_COMMAND_TYPE CommandType = iota + 1 // Default option, a slash command.
	USER_COMMAND_TYPE                              // Mounted to user/member profile.
	MESSAGE_COMMAND_TYPE                           // Mounted to text message.
)

type Component

type Component struct {
	Type         ComponentType       `json:"type"`
	CustomID     string              `json:"custom_id,omitempty"`
	Style        uint8               `json:"style,omitempty"` // Either ButtonStyle or TextInputStyle.
	Label        string              `json:"label,omitempty"`
	Emoji        *PartialEmoji       `json:"emoji,omitempty"`
	URL          string              `json:"url,omitempty"`
	Disabled     bool                `json:"disabled,omitempty"`
	Placeholder  string              `json:"placeholder,omitempty"`
	MinValues    uint64              `json:"min_values,omitempty"`
	MaxValues    uint64              `json:"max_values,omitempty"`
	Required     bool                `json:"required,omitempty"`
	Options      []*SelectMenuOption `json:"options,omitempty"`
	Value        string              `json:"value,omitempty"`         // Contains menu choice or text input value from user modal submit.
	ChannelTypes []*ChannelType      `json:"channel_types,omitempty"` // Only available for 8th ComponentType.
}

Generic Component super struct (because Go doesn't support unions)!

https://discord.com/developers/docs/interactions/message-components#button-object-button-structure

https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-menu-structure

https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure

type ComponentInteraction added in v1.1.0

type ComponentInteraction struct {
	ID              Snowflake                `json:"id"`
	ApplicationID   Snowflake                `json:"application_id"`
	Type            InteractionType          `json:"type"`
	Data            ComponentInteractionData `json:"data"`
	GuildID         Snowflake                `json:"guild_id,omitempty"`
	ChannelID       Snowflake                `json:"channel_id,omitempty"`
	Member          *Member                  `json:"member,omitempty"`
	User            *User                    `json:"user,omitempty"`
	Token           string                   `json:"token"`   // Temporary token used for responding to the interaction. It's not the same as bot/app token.
	Version         uint8                    `json:"version"` // Read-only property, always = 1.
	Message         Message                  `json:"message"`
	PermissionFlags uint64                   `json:"app_permissions,string"` // Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
	Locale          string                   `json:"locale,omitempty"`       // Selected language of the invoking user.
	GuildLocale     string                   `json:"guild_locale,omitempty"` // Guild's preferred locale, available if invoked in a guild.

	Client *Client `json:"-"`
	// contains filtered or unexported fields
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object

func (ComponentInteraction) Acknowledge added in v1.1.0

func (itx ComponentInteraction) Acknowledge() error

Sends to discord info that this component was handled successfully without sending anything more.

func (ComponentInteraction) AcknowledgeWithLinearMessage added in v1.1.0

func (itx ComponentInteraction) AcknowledgeWithLinearMessage(content string, ephemeral bool) error

func (ComponentInteraction) AcknowledgeWithMessage added in v1.1.0

func (itx ComponentInteraction) AcknowledgeWithMessage(content ResponseMessageData, ephemeral bool) error

func (ComponentInteraction) AcknowledgeWithModal added in v1.1.0

func (itx ComponentInteraction) AcknowledgeWithModal(modal ResponseModalData) error

type ComponentInteractionData added in v1.1.0

type ComponentInteractionData struct {
	CustomID string                   `json:"custom_id"`
	Type     ComponentType            `json:"component_type"`
	Values   []string                 `json:"values,omitempty"`
	Resolved *InteractionDataResolved `json:"resolved,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-message-component-data-structure

type ComponentRow added in v1.1.0

type ComponentRow struct {
	Type       ComponentType `json:"type"` // Always 1
	Components []*Component  `json:"components"`
}

https://discord.com/developers/docs/interactions/message-components#action-rows

type ComponentType

type ComponentType uint8
const (
	ROW_COMPONENT_TYPE ComponentType = iota + 1
	BUTTON_COMPONENT_TYPE
	SELECT_MENU_COMPONENT_TYPE
	TEXT_INPUT_COMPONENT_TYPE
	USER_SELECT_COMPONENT_TYPE
	ROLE_SELECT_COMPONENT_TYPE
	MENTIONABLE_SELECT_COMPONENT_TYPE
	CHANNEL_SELECT_COMPONENT_TYPE
)

https://discord.com/developers/docs/interactions/message-components#component-object-component-types

type Embed

type Embed struct {
	Title       string          `json:"title,omitempty"`
	URL         string          `json:"url,omitempty"`
	Author      *EmbedAuthor    `json:"author,omitempty"`
	Color       uint32          `json:"color,omitempty"`
	Thumbnail   *EmbedThumbnail `json:"thumbnail,omitempty"`
	Description string          `json:"description,omitempty"`
	Fields      []*EmbedField   `json:"fields,omitempty"`
	Footer      *EmbedFooter    `json:"footer,omitempty"`
	Image       *EmbedImage     `json:"image,omitempty"`
	Video       *EmbedVideo     `json:"video,omitempty"`
	Provider    *EmbedProvider  `json:"provider,omitempty"`
	Timestamp   *time.Time      `json:"timestamp,omitempty"`
}

https://discord.com/developers/docs/resources/channel#embed-object-embed-structure (always rich embed type)

type EmbedAuthor

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

https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure

type EmbedField

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

https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure

type EmbedFooter

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

https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure

type EmbedImage

type EmbedImage struct {
	URL      string `json:"url"`
	ProxyURL string `json:"proxy_url,omitempty"`
	Width    uint   `json:"width,omitempty"`
	Height   uint   `json:"height,omitempty"`
}

https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure

type EmbedProvider

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

https://discord.com/developers/docs/resources/channel#embed-object-embed-provider-structure

type EmbedThumbnail

type EmbedThumbnail struct {
	URL      string `json:"url"`
	ProxyURL string `json:"proxy_url,omitempty"`
	Width    uint   `json:"width,omitempty"`
	Height   uint   `json:"height,omitempty"`
}

https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure

type EmbedVideo

type EmbedVideo struct {
	URL    string `json:"url,omitempty"`
	Width  uint   `json:"width,omitempty"`
	Height uint   `json:"height,omitempty"`
}

https://discord.com/developers/docs/resources/channel#embed-object-embed-video-structure

type Emoji

type Emoji struct {
	ID            Snowflake   `json:"id,omitempty"`
	Name          string      `json:"name"`
	Roles         []Snowflake `json:"roles,omitempty"`
	User          *User       `json:"user,omitempty"`
	RequireColons bool        `json:"require_colons,omitempty"`
	Managed       bool        `json:"managed,omitempty"`
	Animated      bool        `json:"animated,omitempty"`
	Available     bool        `json:"available,omitempty"`
}

https://discord.com/developers/docs/resources/emoji#emoji-object-emoji-structure

type InteractionDataResolved

type InteractionDataResolved struct {
	Users    map[Snowflake]*User           `json:"users,omitempty"`
	Members  map[Snowflake]*Member         `json:"members,omitempty"`
	Roles    map[Snowflake]*Role           `json:"roles,omitempty"`
	Channels map[Snowflake]*PartialChannel `json:"channels,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure

type InteractionType

type InteractionType uint8

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type

const (
	PING_INTERACTION_TYPE InteractionType = iota + 1
	APPLICATION_COMMAND_INTERACTION_TYPE
	MESSAGE_COMPONENT_INTERACTION_TYPE
	APPLICATION_COMMAND_AUTO_COMPLETE_INTERACTION_TYPE
	MODAL_SUBMIT_INTERACTION_TYPE
)

type InteractionTypeExtractor added in v1.1.0

type InteractionTypeExtractor struct {
	Type InteractionType `json:"type"`
}

Used only for partial JSON parsing.

type Language added in v1.1.4

type Language string

https://discord.com/developers/docs/reference#locales

const (
	DANISH_LANGUAGE         Language = "da"
	GERMAN_LANGUAGE         Language = "de"
	ENGLISH_UK_LANGUAGE     Language = "en-GB"
	ENGLISH_US_LANGUAGE     Language = "en-US"
	SPANISH_LANGUAGE        Language = "es-ES"
	FRENCH_LANGUAGE         Language = "fr"
	CROATIAN_LANGUAGE       Language = "hr"
	ITALIAN_LANGUAGE        Language = "it"
	LITHUANIAN_LANGUAGE     Language = "lt"
	HUNGARIAN_LANGUAGE      Language = "hu"
	DUTCH_LANGUAGE          Language = "nl"
	NORWEGIAN_LANGUAGE      Language = "no"
	POLISH_LANGUAGE         Language = "pl"
	PORTUGUESE_BR_LANGUAGE  Language = "pt-BR"
	ROMANIAN_LANGUAGE       Language = "ro"
	FINNISH_LANGUAGE        Language = "fi"
	SWEDISH_LANGUAGE        Language = "sv-SE"
	VIETNAMESE_LANGUAGE     Language = "vi"
	TURKISH_LANGUAGE        Language = "tr"
	CHECH_LANGUAGE          Language = "cs"
	GREEK_LANGUAGE          Language = "el"
	BULGARIAN_LANGUAGE      Language = "bg"
	RUSSIAN_LANGUAGE        Language = "ru"
	UKRAINIAN_LANGUAGE      Language = "uk"
	HINDI_LANGUAGE          Language = "hi"
	THAI_LANGUAGE           Language = "th"
	CHINESE_CHINA_LANGUAGE  Language = "zh-CN"
	JAPANESE_LANGUAGE       Language = "ja"
	CHINESE_TAIWAN_LANGUAGE Language = "zh-TW"
	KOREAN_LANGUAGE         Language = "ko"
)

type Member

type Member struct {
	User                       *User       `json:"user,omitempty"`
	Nickname                   string      `json:"nick,omitempty"`
	GuildAvatarHash            string      `json:"avatar,omitempty"` // Hash code used to access member's custom, guild profile. Call Member.GuildAvatarURL to get direct url.
	RoleIDs                    []Snowflake `json:"roles"`
	JoinedAt                   *time.Time  `json:"joined_at,omitempty"`
	PremiumSince               *time.Time  `json:"premium_since,omitempty"`
	Dead                       bool        `json:"deaf"`
	Mute                       bool        `json:"mute"`
	Flags                      uint64      `json:"flags"`
	Pending                    bool        `json:"pending,omitempty"`
	PermissionFlags            uint64      `json:"permissions,string"`
	CommunicationDisabledUntil *time.Time  `json:"communication_disabled_until,omitempty"`
	GuildID                    Snowflake   `json:"-"`
}

https://discord.com/developers/docs/resources/guild#guild-member-object-guild-member-structure

func (Member) GuildAvatarURL added in v1.1.0

func (member Member) GuildAvatarURL() string

Returns a direct url to members's guild specific avatar. It'll return empty string if targeted member don't use custom avatar for that server.

type Message

type Message struct {
	ID                Snowflake           `json:"id"`
	ChannelID         Snowflake           `json:"channel_id"`
	Author            *User               `json:"author,omitempty"`
	Content           string              `json:"content,omitempty"`
	Timestamp         *time.Time          `json:"timestamp"`
	EditedTimestamp   *time.Time          `json:"edited_timestamp,omitempty"`
	TTS               bool                `json:"tts"`
	MentionEveryone   bool                `json:"mention_everyone"`
	Mentions          []*User             `json:"mentions"`
	MentionRoles      []*Snowflake        `json:"mention_roles"`
	MentionChannels   []*ChannelMention   `json:"mention_channels,omitempty"`
	Embeds            []*Embed            `json:"embeds"`
	Reactions         []*Reaction         `json:"reactions,omitempty"`
	Pinned            bool                `json:"pinned"`
	WebhookID         Snowflake           `json:"webhook_id,omitempty"`
	Type              uint                `json:"type,omitempty"` // https://discord.com/developers/docs/resources/channel#message-object-message-types
	ApplicationID     Snowflake           `json:"application_id,omitempty"`
	MessageReference  *MessageReference   `json:"message_reference,omitempty"`
	Flags             uint64              `json:"flags,omitempty"`
	ReferencedMessage *Message            `json:"referenced_message,omitempty"`
	Interaction       *MessageInteraction `json:"interaction,omitempty"`
	Components        []*ComponentRow     `json:"components,omitempty"`
	StickerItems      []*StickerItem      `json:"sticker_items,omitempty"`
}

https://discord.com/developers/docs/resources/channel#message-object-message-structure

type MessageInteraction added in v1.1.0

type MessageInteraction struct {
	ID     Snowflake       `json:"id"`
	Type   InteractionType `json:"type"`
	Name   string          `json:"name"`
	User   User            `json:"user"`
	Member *Member         `json:"member,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object-message-interaction-structure

type MessageReference

type MessageReference struct {
	MessageID       Snowflake `json:"message_id,omitempty"`
	ChannelID       Snowflake `json:"channel_id,omitempty"`
	GuildID         Snowflake `json:"guild_id,omitempty"`
	FailIfNotExists bool      `json:"fail_if_not_exists,omitempty"`
}

https://discord.com/developers/docs/resources/channel#message-reference-object-message-reference-structure

type ModalInteraction added in v1.1.0

type ModalInteraction struct {
	ID              Snowflake            `json:"id"`
	ApplicationID   Snowflake            `json:"application_id"`
	Type            InteractionType      `json:"type"`
	Data            ModalInteractionData `json:"data"`
	GuildID         Snowflake            `json:"guild_id,omitempty"`
	ChannelID       Snowflake            `json:"channel_id,omitempty"`
	Member          *Member              `json:"member,omitempty"`
	User            *User                `json:"user,omitempty"`
	Token           string               `json:"token"`                  // Temporary token used for responding to the interaction. It's not the same as bot/app token.
	Version         uint8                `json:"version"`                // Read-only property, always = 1.
	PermissionFlags uint64               `json:"app_permissions,string"` // Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
	Locale          string               `json:"locale,omitempty"`       // Selected language of the invoking user.
	GuildLocale     string               `json:"guild_locale,omitempty"` // Guild's preferred locale, available if invoked in a guild.

	Client *Client `json:"-"`
	// contains filtered or unexported fields
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object

func (ModalInteraction) Acknowledge added in v1.1.0

func (itx ModalInteraction) Acknowledge() error

Sends to discord info that this component was handled successfully without sending anything more.

func (ModalInteraction) AcknowledgeWithLinearMessage added in v1.1.0

func (itx ModalInteraction) AcknowledgeWithLinearMessage(content string, ephemeral bool) error

func (ModalInteraction) AcknowledgeWithMessage added in v1.1.0

func (itx ModalInteraction) AcknowledgeWithMessage(response ResponseMessageData, ephemeral bool) error

func (ModalInteraction) AcknowledgeWithModal added in v1.1.0

func (itx ModalInteraction) AcknowledgeWithModal(modal ResponseModalData) error

func (ModalInteraction) GetInputValue added in v1.1.0

func (itx ModalInteraction) GetInputValue(customID string) string

Returns value of any type. It will return empty string on no value or empty value.

type ModalInteractionData added in v1.1.0

type ModalInteractionData struct {
	CustomID   string         `json:"custom_id"`
	Components []ComponentRow `json:"components"`
}

type NitroType added in v1.1.0

type NitroType uint8

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

const (
	NO_NITRO_TYPE NitroType = iota
	CLASSIC_NITRO_TYPE
	FULL_NITRO_TYPE
	BASIC_NITRO_TYPE
)

type OptionType

type OptionType uint8

https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type

const (
	SUB_OPTION_TYPE OptionType = iota + 1

	STRING_OPTION_TYPE
	INTEGER_OPTION_TYPE
	BOOLEAN_OPTION_TYPE
	USER_OPTION_TYPE
	CHANNEL_OPTION_TYPE
	ROLE_OPTION_TYPE
	MENTIONABLE_OPTION_TYPE
	NUMBER_OPTION_TYPE
	ATTACHMENT_OPTION_TYPE
)

type PartialChannel added in v1.0.3

type PartialChannel struct {
	ID              Snowflake   `json:"id"`
	Name            string      `json:"name"`
	PermissionFlags uint64      `json:"permissions,string"`
	Type            ChannelType `json:"type"`
}

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

type PartialEmoji

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

https://discord.com/developers/docs/resources/emoji#emoji-object-emoji-structure

type Reaction added in v1.1.0

type Reaction struct {
	Count uint          `json:"count"`
	Me    bool          `json:"me"`
	Emoji *PartialEmoji `json:"emoji"`
}

https://discord.com/developers/docs/resources/channel#reaction-object-reaction-structure

type ResponseAutoComplete added in v1.1.0

type ResponseAutoComplete struct {
	Type ResponseType              `json:"type"`
	Data *ResponseAutoCompleteData `json:"data,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object

type ResponseAutoCompleteData added in v1.1.0

type ResponseAutoCompleteData struct {
	Choices []Choice `json:"choices,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-autocomplete

type ResponseMessage added in v1.1.0

type ResponseMessage struct {
	Type ResponseType         `json:"type"`
	Data *ResponseMessageData `json:"data,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object

type ResponseMessageData added in v1.1.0

type ResponseMessageData struct {
	TTS             bool             `json:"tts,omitempty"`
	Content         string           `json:"content,omitempty"`
	Embeds          []*Embed         `json:"embeds,omitempty"`
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
	Flags           uint64           `json:"flags,omitempty"`
	Components      []*ComponentRow  `json:"components,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-messages

type ResponseModal added in v1.0.4

type ResponseModal struct {
	Type ResponseType       `json:"type"`
	Data *ResponseModalData `json:"data,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object

type ResponseModalData added in v1.0.4

type ResponseModalData struct {
	CustomID   string          `json:"custom_id"`
	Title      string          `json:"title"`
	Components []*ComponentRow `json:"components,omitempty"`
}

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal

type ResponseType

type ResponseType uint8

https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-callback-type

const (
	PONG_RESPONSE_TYPE ResponseType = iota + 1
	ACKNOWLEDGE_RESPONSE_TYPE
	CHANNEL_MESSAGE_RESPONSE_TYPE
	CHANNEL_MESSAGE_WITH_SOURCE_RESPONSE_TYPE
	DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE_RESPONSE_TYPE
	DEFERRED_UPDATE_MESSAGE_RESPONSE_TYPE // Only valid for component-based interactions.
	UPDATE_MESSAGE_RESPONSE_TYPE          // Only valid for component-based interactions.
	AUTOCOMPLETE_RESPONSE_TYPE
	MODAL_RESPONSE_TYPE // Not available for MODAL_SUBMIT and PING interactions.
)

type RestClient added in v1.2.0

type RestClient struct {
	HTTPClient *http.Client
	Token      string
	MaxRetries uint8
	// contains filtered or unexported fields
}

func NewRestClient added in v1.2.0

func NewRestClient(token string) *RestClient

func (*RestClient) Request added in v1.2.0

func (rest *RestClient) Request(method string, route string, jsonPayload interface{}) ([]byte, error)

func (*RestClient) RequestWithFiles added in v1.2.0

func (rest *RestClient) RequestWithFiles(method string, route string, jsonPayload interface{}, files []*os.File) ([]byte, error)

type Role

type Role struct {
	ID              Snowflake `json:"id"`
	Name            string    `json:"name"`
	Color           uint32    `json:"color"` // Integer representation of hexadecimal color code. Roles without colors (color == 0) do not count towards the final computed color in the user list.
	Hoist           bool      `json:"hoist"` // Whether this role is pinned in the user listing.
	IconHash        string    `json:"icon,omitempty"`
	UnicodeEmoji    string    `json:"unicode_emoji,omitempty"`
	Position        uint8     `json:"position"`
	PermissionFlags uint64    `json:"permissions,string"`
	Managed         bool      `json:"managed"`     // Whether this role is managed by an integration.
	Mentionable     bool      `json:"mentionable"` // Whether this role is mentionable.
	Tags            *RoleTag  `json:"tags,omitempty"`
}

https://discord.com/developers/docs/topics/permissions#role-object-role-structure

func (Role) IconURL added in v1.1.0

func (role Role) IconURL() string

Returns a direct url to role icon. It'll return empty string if there's no custom icon.

func (Role) Mention added in v1.2.0

func (role Role) Mention() string

type RoleTag

type RoleTag struct {
	BotID                 Snowflake `json:"bot_id,omitempty"`
	IntegrationID         Snowflake `json:"integration_id,omitempty"`          // The id of the integration this role belongs to.
	PremiumSubscriber     bool      `json:"premium_subscriber,omitempty"`      // Whether this is the guild's Booster role.
	SubscriptionListingID Snowflake `json:"subscription_listing_id,omitempty"` // The id of this role's subscription sku and listing.
	AvailableForPurchase  bool      `json:"available_for_purchase,omitempty"`
	GuildConnections      bool      `json:"guild_connections,omitempty"` // Whether this role is a guild's linked role.
}

https://discord.com/developers/docs/topics/permissions#role-object-role-tags-structure

type SelectMenuOption

type SelectMenuOption struct {
	Label       string        `json:"label,omitempty"`       // Text label that appears on the option label, max 80 characters.
	Description string        `json:"description,omitempty"` // An additional description of the option, max 100 characters.
	Emoji       *PartialEmoji `json:"emoji,omitempty"`
	Value       string        `json:"value"`   // Value to return back to app once clicked, max 100 characters.
	Default     bool          `json:"default"` // Whether to render this option as selected by default.
}

https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure

type Snowflake

type Snowflake uint64

Snowflake represents a Discord's id snowflake.

func EnvToSnowflake added in v1.1.4

func EnvToSnowflake(key string) (Snowflake, error)

Shortcut to calling os.Getenv method and casting to Snowflake.

func StringToSnowflake

func StringToSnowflake(s string) (Snowflake, error)

func (Snowflake) CreationTimestamp added in v1.1.0

func (s Snowflake) CreationTimestamp() time.Time

func (Snowflake) MarshalJSON

func (s Snowflake) MarshalJSON() ([]byte, error)

func (Snowflake) String

func (s Snowflake) String() string

func (*Snowflake) UnmarshalJSON

func (s *Snowflake) UnmarshalJSON(b []byte) error

type StickerFormatType added in v1.1.0

type StickerFormatType uint8

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

const (
	PNG_STICKER_FORMAT_TYPE StickerFormatType = iota + 1
	APNG_STICKER_FORMAT_TYPE
	LOTTIE_STICKER_FORMAT_TYPE
	GIF_STICKER_FORMAT_TYPE
)

type StickerItem added in v1.1.0

type StickerItem struct {
	ID         Snowflake         `json:"id"`
	Name       string            `json:"name"`
	FormatType StickerFormatType `json:"format_type"`
}

https://discord.com/developers/docs/resources/sticker#sticker-item-object-sticker-item-structure

type TextInputStyle

type TextInputStyle uint8

https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles

const (
	SHORT_TEXT_INPUT_STYLE     TextInputStyle = iota + 1 // 	A single-line input.
	PARAGRAPH_TEXT_INPUT_STYLE                           // A multi-line input.
)

type User

type User struct {
	ID          Snowflake `json:"id"`
	Username    string    `json:"username"`
	GlobalName  string    `json:"global_name,omitempty"` // User's display name, if it is set. For bots, this is the application name.
	AvatarHash  string    `json:"avatar,omitempty"`      // Hash code used to access user's profile. Call User.AvatarURL to get direct url.
	Bot         bool      `json:"bot,omitempty"`
	MFA         bool      `json:"mfa_enabled,omitempty"`
	BannerHash  string    `json:"banner,omitempty"`       // Hash code used to access user's baner. Call User.BannerURL to get direct url.
	AccentColor uint32    `json:"accent_color,omitempty"` // User's banner color, encoded as an integer representation of hexadecimal color code.
	Locale      string    `json:"locale,omitempty"`
	PremiumType NitroType `json:"premium_type,omitempty"`
	PublicFlags uint64    `json:"public_flags,omitempty"` // (Same as regular flags)
}

https://discord.com/developers/docs/resources/user#user-object-user-structure

func (User) AvatarURL added in v1.1.0

func (user User) AvatarURL() string

Returns a direct url to user's avatar. It'll return url to default Discord's avatar if targeted user don't use avatar.

func (User) BannerURL added in v1.1.0

func (user User) BannerURL() string

Returns a direct url to user's banner. It'll return empty string if targeted user don't use avatar.

func (User) Mention

func (user User) Mention() string

Jump to

Keyboard shortcuts

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