discgo

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: MIT Imports: 8 Imported by: 1

README

Discgo

A Discord API client library written in Go

This is not a full client, and is intended to provide support for certain Discord API interactions as I have the need. Perhaps in time full support will be added. Contributions are welcome.

Yes, there are other libraries that have been out for a while which are more actively developed, but I have my own reasons and goals for creating this project:

  • Better support for metrics and tracing
  • Better ruser of context
  • Better control of logging and error handling
  • A package structure I like
  • Respect SemVer, even if semantic import versioning sucks
  • Because I want to

Features

  • Separate REST API client and Gateway Clients. Use one or both as you like.
    • although, you'll probably need to use the REST client to initialize the Gateway client
  • Functional options for configuring your client

Using the Gateway Client

TBD

Documentation

Index

Constants

View Source
const (
	// EventHello defines the heartbeat interval
	EventHello = "HELLO"
	// EventReady contains the initial state information
	EventReady = "READY"
	// EventResumed response to Resume
	EventResumed = "RESUMED"
	// EventReconnect server is going away
	EventReconnect = "RECONNECT"
	// EventInvalidSession failure response to Identify or Resume or invalid active session
	EventInvalidSession = "INVALID_SESSION"
	// EventApplicationCommandCreate new Slash Command was created
	EventApplicationCommandCreate = "APPLICATION_COMMAND_CREATE"
	// EventApplicationCommandUpdate Slash Command was updated
	EventApplicationCommandUpdate = "APPLICATION_COMMAND_UPDATE"
	// EventApplicationCommandDelete Slash Command was deleted
	EventApplicationCommandDelete = "APPLICATION_COMMAND_DELETE"
	// EventChannelCreate new guild channel created
	EventChannelCreate = "CHANNEL_CREATE"
	// EventChannelUpdate channel was updated
	EventChannelUpdate = "CHANNEL_UPDATE"
	// EventChannelDelete channel was deleted
	EventChannelDelete = "CHANNEL_DELETE"
	// EventChannelPinsUpdate message was pinned or unpinned
	EventChannelPinsUpdate = "CHANNEL_PINS_UPDATE"
	// EventThreadCreate thread created
	EventThreadCreate = "THREAD_CREATE"
	// EventThreadUpdate thread was updated
	EventThreadUpdate = "THREAD_UPDATE"
	// EventThreadDelete thread was deleted
	EventThreadDelete = "THREAD_DELETE"
	// EventThreadListSync sent when gaining access to a channel
	EventThreadListSync = "THREAD_LIST_SYNC"
	// EventThreadMemberUpdate thread member for the current user was updated
	EventThreadMemberUpdate = "THREAD_MEMBER_UPDATE"
	// EventThreadMembersUpdate some user(s) were added to or removed from a thread
	EventThreadMembersUpdate = "THREAD_MEMBERS_UPDATE"
	// EventGuildCreate lazy-load for unavailable guild
	EventGuildCreate = "GUILD_CREATE"
	// EventGuildUpdate guild was updated
	EventGuildUpdate = "GUILD_UPDATE"
	// EventGuildDelete guild became unavailable
	EventGuildDelete = "GUILD_DELETE"
	// EventGuildBanAdd user was banned from a guild
	EventGuildBanAdd = "GUILD_BAN_ADD"
	// EventGuildBanRemove user was unbanned from a guild
	EventGuildBanRemove = "GUILD_BAN_REMOVE"
	// EventGuildEmojisUpdate guild emojis were updated
	EventGuildEmojisUpdate = "GUILD_EMOJIS_UPDATE"
	// EventGuildIntegrationsUpdate guild integration was updated
	EventGuildIntegrationsUpdate = "GUILD_INTEGRATIONS_UPDATE"
	// EventGuildMemberAdd new user joined a guild
	EventGuildMemberAdd = "GUILD_MEMBER_ADD"
	// EventGuildMemberRemove user was removed from a guild
	EventGuildMemberRemove = "GUILD_MEMBER_REMOVE"
	// EventGuildMemberUpdate guild member was updated
	EventGuildMemberUpdate = "GUILD_MEMBER_UPDATE"
	// EventGuildMembersChunk response to Request Guild Members
	EventGuildMembersChunk = "GUILD_MEMBERS_CHUNK"
	// EventGuildRoleCreate guild role was created
	EventGuildRoleCreate = "GUILD_ROLE_CREATE"
	// EventGuildRoleUpdate guild role was updated
	EventGuildRoleUpdate = "GUILD_ROLE_UPDATE"
	// EventGuildRoleDelete guild role was deleted
	EventGuildRoleDelete = "GUILD_ROLE_DELETE"
	// EventIntegrationCreate guild integration was created
	EventIntegrationCreate = "INTEGRATION_CREATE"
	// EventIntegrationUpdate guild integration was updated
	EventIntegrationUpdate = "INTEGRATION_UPDATE"
	// EventIntegrationDelete guild integration was deleted
	EventIntegrationDelete = "INTEGRATION_DELETE"
	// EventInteractionCreate user used an interaction
	EventInteractionCreate = "INTERACTION_CREATE"
	// EventInviteCreate invite to a channel was created
	EventInviteCreate = "INVITE_CREATE"
	// EventInviteDelete invite to a channel was deleted
	EventInviteDelete = "INVITE_DELETE"
	// EventMessageCreate message was created
	EventMessageCreate = "MESSAGE_CREATE"
	// EventMessageUpdate message was edited
	EventMessageUpdate = "MESSAGE_UPDATE"
	// EventMessageDelete message was deleted
	EventMessageDelete = "MESSAGE_DELETE"
	// EventMessageDeleteBulk multiple messages were deleted at once
	EventMessageDeleteBulk = "MESSAGE_DELETE_BULK"
	// EventMessageReactionAdd user reacted to a message
	EventMessageReactionAdd = "MESSAGE_REACTION_ADD"
	// EventMessageReactionRemove user removed a reaction from a message
	EventMessageReactionRemove = "MESSAGE_REACTION_REMOVE"
	// EventMessageReactionRemoveAll all reactions were explicitly removed from a message
	EventMessageReactionRemoveAll = "MESSAGE_REACTION_REMOVE_ALL"
	// EventMessageReactionRemoveEmoji all reactions for a given emoji were explicitly removed from a message
	EventMessageReactionRemoveEmoji = "MESSAGE_REACTION_REMOVE_EMOJI"
	// EventPresenceUpdate user was updated
	EventPresenceUpdate = "PRESENCE_UPDATE"
	// EventStageInstanceCreate stage instance was created
	EventStageInstanceCreate = "STAGE_INSTANCE_CREATE"
	// EventStageInstanceDelete stage instance was deleted or closed
	EventStageInstanceDelete = "STAGE_INSTANCE_DELETE"
	// EventStageInstanceUpdate stage instance was updated
	EventStageInstanceUpdate = "STAGE_INSTANCE_UPDATE"
	// EventTypingStart user started typing in a channel
	EventTypingStart = "TYPING_START"
	// EventUserUpdate properties about the user changed
	EventUserUpdate = "USER_UPDATE"
	// EventVoiceStateUpdate someone joined
	EventVoiceStateUpdate = "VOICE_STATE_UPDATE"
	// EventVoiceServerUpdate guild's voice server was updated
	EventVoiceServerUpdate = "VOICE_SERVER_UPDATE"
	// EventWebhooksUpdate guild channel webhook was created
	EventWebhooksUpdate = "WEBHOOKS_UPDATE"
)
View Source
const (
	// Guild
	IntentGuildCreate = iota + 1<<0
	IntentGuildUpdate
	IntentGuildDelete
	IntentGuildRoleCreate
	IntentGuildRoleUpdate
	IntentGuildRoleDelete
	IntentChannelCreate
	IntentChannelUpdate
	IntentChannelDelete
	IntentChannelPinsUpdate
	IntentThreadCreate
	IntentThreadUpdate
	IntentThreadDelete
	IntentThreadListSync
	IntentThreadMemberUpdate
	IntentGuildThreadMembersUpdate
	IntentStageInstanceCreate
	IntentStageInstanceUpdate
	IntentStageInstanceDelete

	// Guild Members
	IntentGuildMemberAdd = iota + 1<<1
	IntentGuildMemberUpdate
	IntentGuildMemberRemove
	IntentMembersThreadMembersUpdate

	// Guild Bans
	IntentGuildBanAdd = iota + 1<<2
	IntentGuildBanRemove

	//Guild Emojis
	IntentGuildEmojisUpdate = iota + 1<<3

	// Guild Integrations
	IntentGuildintegrationsUpdate = iota + 1<<4
	IntentIntegrationCreate
	IntentIntegrationUpdate
	IntentIntegrationDelete

	// Guild Webhooks
	IntentWebhooksUpdate = iota + 1<<5

	// Guild Invites
	IntentInviteCreate = iota + 1<<6
	IntentInviteDelete

	// Guild Voice States
	IntentVoiceStateUpdate = iota + 1<<7

	// Guild Presences
	IntentPresenceUpdate = iota + 1<<8

	// Guild Messages
	IntentMessageCreate = iota + 1<<9
	IntentMessageUpdate
	IntentMessageDelete
	IntentMessageDeleteBulk

	// Guild Message Reactions
	IntentMessageReactionAdd = iota + 1<<10
	IntentMessageReactionRemove
	IntentMessageReactionRemoveAll
	IntentMessageReactionRemoveEmoji

	// Guild Message Typing
	IntentTypingStart = iota + 1<<11

	// Direct Messages
	IntentDirectMessageCreate = iota + 1<<12
	IntentDirectMessageUpdate
	IntentDirectMessageDelete
	IntentDirectMessageChannelPinsUpdate

	// Direct Message Reactions
	IntentDirectMessageReactionAdd = iota + 1<<13
	IntentDirectMessageReactionRemove
	IntentDirectMessageReactionRemoveAll
	IntentDirectMessageReactionRemoveEmoji

	// Direct Message Typing
	IntentDirectMessageTypingStart = iota + 1<<14
)
View Source
const (
	OpCodeDispatch            = 0
	OpCodeHeartbeat           = 1
	OpCodeIdentify            = 2
	OpCodePresenceUpdate      = 3
	OpCodeVoiceStateUpdate    = 4
	OpCodeResume              = 6
	OpCodeReconnect           = 7
	OpCodeRequestGuildMembers = 8
	OpCodeInvalidSession      = 9
	OpCodeHello               = 10
	OpCodeHeartbeatACK        = 11
)
View Source
const (
	GetGatewayBotURL = "/gateway/bot"
)

Variables

This section is empty.

Functions

func DataToStruct

func DataToStruct(source interface{}, target interface{}) error

DataToStruct takes a JSON marshallable struct and Unmarshals it to the target pointer value

Types

type Activity

type Activity struct {
	// Name the activity's name
	Name string `json:"name"`
	// Type [activity type](#DOCS_TOPICS_GATEWAY/activity-object-activity-types)
	Type int `json:"type"`
	// Url stream url, is validated when type is 1
	Url string `json:"url"`
	// CreatedAt unix timestamp (in milliseconds) of when the activity was added to the user's session
	CreatedAt int `json:"created_at"`
	// Timestamps unix timestamps for start and/or end of the game
	Timestamps ActivityTimestamps `json:"timestamps"`
	// ApplicationId application id for the game
	ApplicationId string `json:"application_id"`
	// Details what the player is currently doing
	Details string `json:"details"`
	// State the user's current party status
	State string `json:"state"`
	// Emoji the emoji used for a custom status
	Emoji ActivityEmoji `json:"emoji"`
	// Party information for the current party of the player
	Party ActivityParty `json:"party"`
	// Assets images for the presence and their hover texts
	Assets ActivityAssets `json:"assets"`
	// Secrets secrets for Rich Presence joining and spectating
	Secrets ActivitySecrets `json:"secrets"`
	// Instance whether or not the activity is an instanced game session
	Instance bool `json:"instance"`
	// Flags [activity flags](#DOCS_TOPICS_GATEWAY/activity-object-activity-flags) `OR`d together, describes what the payload includes
	Flags int `json:"flags"`
	// Buttons the custom buttons shown in the Rich Presence (max 2)
	Buttons []ActivityButtons `json:"buttons"`
}

type ActivityAssets

type ActivityAssets struct {
	LargeImage string `json:"large_image"`
	LargeText  string `json:"large_text"`
	SmallImage string `json:"small_image"`
	SmallText  string `json:"small_text"`
}

type ActivityButtons

type ActivityButtons struct {
	// Label the text shown on the button (1-32 characters)
	Label string `json:"label"`
	// Url the url opened when clicking the button (1-512 characters)
	Url string `json:"url"`
}

type ActivityEmoji

type ActivityEmoji struct {
	Name     string `json:"name"`
	Id       string `json:"id"`
	Animated bool   `json:"animated"`
}

type ActivityParty

type ActivityParty struct {
	Id   string `json:"id"`
	Size []int  `json:"size"`
}

type ActivitySecrets

type ActivitySecrets struct {
	Join     string `json:"join"`
	Spectate string `json:"spectate"`
	Match    string `json:"match"`
}

type ActivityTimestamps

type ActivityTimestamps struct {
	Start int `json:"start"`
	End   int `json:"end"`
}

type AllowedMentionType

type AllowedMentionType string
const (
	AllowedMentionRole     AllowedMentionType = "roles"
	AllowedMentionUser     AllowedMentionType = "users"
	AllowedMentionEveryone AllowedMentionType = "everyone"
)

type AllowedMentions

type AllowedMentions struct {
	// Parse An array of [allowed mention types](#DOCS_RESOURCES_CHANNEL/allowed-mentions-object-allowed-mention-types) to parse from the content.
	Parse []AllowedMentionType `json:"parse"`
	// Roles Array of role_ids to mention (Max size of 100)
	Roles string `json:"roles"`
	// Users Array of user_ids to mention (Max size of 100)
	Users string `json:"users"`
	// RepliedUser For replies, whether to mention the author of the message being replied to (default false)
	RepliedUser bool `json:"replied_user"`
}

type ApiClient

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

func NewApiClient

func NewApiClient(options ...ApiClientOption) *ApiClient

func (*ApiClient) Close

func (d *ApiClient) Close()

func (*ApiClient) Do

func (d *ApiClient) Do(req *http.Request) (*http.Response, error)

Do adds headers before calling DiscordClient.http.Do

func (*ApiClient) GetGatewayBot

func (d *ApiClient) GetGatewayBot(ctx context.Context) (*GetGatewayBotResponse, *http.Response, error)

type ApiClientOption

type ApiClientOption func(*ApiClient)

func WithApiConfig

func WithApiConfig(cfg *ApiConfig) ApiClientOption

func WithClientLogger

func WithClientLogger(l Logger) ApiClientOption

func WithHttpClient

func WithHttpClient(c HTTPClient) ApiClientOption

type ApiConfig

type ApiConfig struct {
	APIBaseURL    string
	ApplicationID string
	PublicKey     string
	ClientID      string
	ClientSecret  string
	BotToken      string
}

type Application

type Application struct {
	// Id the id of the app
	Id string `json:"id"`
	// Name the name of the app
	Name string `json:"name"`
	// Icon the [icon hash](#DOCS_REFERENCE/image-formatting) of the app
	Icon string `json:"icon"`
	// Description the description of the app
	Description string `json:"description"`
	// RpcOrigins an array of rpc origin urls, if rpc is enabled
	RpcOrigins []string `json:"rpc_origins"`
	// BotPublic when false only app owner can join the app's bot to guilds
	BotPublic bool `json:"bot_public"`
	// BotRequireCodeGrant when true the app's bot will only join upon completion of the full oauth2 code grant flow
	BotRequireCodeGrant bool `json:"bot_require_code_grant"`
	// TermsOfServiceUrl the url of the app's terms of service
	TermsOfServiceUrl string `json:"terms_of_service_url"`
	// PrivacyPolicyUrl the url of the app's privacy policy
	PrivacyPolicyUrl string `json:"privacy_policy_url"`
	// Owner partial user object containing info on the owner of the application
	Owner User `json:"owner"`
	// Summary if this application is a game sold on Discord, this field will be the summary field for the store page of its primary sku
	Summary string `json:"summary"`
	// VerifyKey the hex encoded key for verification in interactions and the GameSDK's [GetTicket](#DOCS_GAME_SDK_APPLICATIONS/getticket)
	VerifyKey string `json:"verify_key"`
	// Team if the application belongs to a team, this will be a list of the members of that team
	Team Team `json:"team"`
	// GuildId if this application is a game sold on Discord, this field will be the guild to which it has been linked
	GuildId string `json:"guild_id"`
	// PrimarySkuId if this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists
	PrimarySkuId string `json:"primary_sku_id"`
	// Slug if this application is a game sold on Discord, this field will be the URL slug that links to the store page
	Slug string `json:"slug"`
	// CoverImage the application's default rich presence invite [cover image hash](#DOCS_REFERENCE/image-formatting)
	CoverImage string `json:"cover_image"`
	// Flags the application's public [flags](#DOCS_RESOURCES_APPLICATION/application-object-application-flags)
	Flags int `json:"flags"`
}

type Attachment

type Attachment struct {
	// Id attachment id
	Id string `json:"id"`
	// Filename name of file attached
	Filename string `json:"filename"`
	// ContentType the attachment's [media type](https://en.wikipedia.org/wiki/Media_type)
	ContentType string `json:"content_type"`
	// Size size of file in bytes
	Size int `json:"size"`
	// Url source url of file
	Url string `json:"url"`
	// ProxyUrl a proxied url of file
	ProxyUrl string `json:"proxy_url"`
	// Height height of file (if image)
	Height int `json:"height"`
	// Width width of file (if image)
	Width int `json:"width"`
}

type Channel

type Channel struct {
	// Id the id of this channel
	Id string `json:"id"`
	// Type the [type of channel](#DOCS_RESOURCES_CHANNEL/channel-object-channel-types)
	Type int `json:"type"`
	// GuildId the id of the guild (may be missing for some channel objects received over gateway guild dispatches)
	GuildId string `json:"guild_id"`
	// Position sorting position of the channel
	Position int `json:"position"`
	// PermissionOverwrites explicit permission overwrites for members and roles
	PermissionOverwrites []Overwrite `json:"permission_overwrites"`
	// Name the name of the channel (1-100 characters)
	Name string `json:"name"`
	// Topic the channel topic (0-1024 characters)
	Topic string `json:"topic"`
	// Nsfw whether the channel is nsfw
	Nsfw bool `json:"nsfw"`
	// LastMessageId the id of the last message sent in this channel (may not point to an existing or valid message)
	LastMessageId string `json:"last_message_id"`
	// Bitrate the bitrate (in bits) of the voice channel
	Bitrate int `json:"bitrate"`
	// UserLimit the user limit of the voice channel
	UserLimit int `json:"user_limit"`
	// RateLimitPerUser amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected
	RateLimitPerUser int `json:"rate_limit_per_user"`
	// Recipients the recipients of the DM
	Recipients []User `json:"recipients"`
	// Icon icon hash
	Icon string `json:"icon"`
	// OwnerId id of the creator of the group DM or thread
	OwnerId string `json:"owner_id"`
	// ApplicationId application id of the group DM creator if it is bot-created
	ApplicationId string `json:"application_id"`
	// ParentId for guild channels: id of the parent category for a channel (each parent category can contain up to 50 channels), for threads: id of the text channel this thread was created
	ParentId string `json:"parent_id"`
	// LastPinTimestamp when the last pinned message was pinned. This may be `null` in events such as `GUILD_CREATE` when a message is not pinned.
	LastPinTimestamp time.Time `json:"last_pin_timestamp"`
	// RtcRegion [voice region](#DOCS_RESOURCES_VOICE/voice-region-object) id for the voice channel, automatic when set to null
	RtcRegion string `json:"rtc_region"`
	// VideoQualityMode the camera [video quality mode](#DOCS_RESOURCES_CHANNEL/channel-object-video-quality-modes) of the voice channel, 1 when not present
	VideoQualityMode int `json:"video_quality_mode"`
	// MessageCount an approximate count of messages in a thread, stops counting at 50
	MessageCount int `json:"message_count"`
	// MemberCount an approximate count of users in a thread, stops counting at 50
	MemberCount int `json:"member_count"`
	// ThreadMetadata thread-specific fields not needed by other channels
	ThreadMetadata ThreadMetadata `json:"thread_metadata"`
	// Member thread member object for the current user, if they have joined the thread, only included on certain API endpoints
	Member ThreadMember `json:"member"`
	// DefaultAutoArchiveDuration default duration for newly created threads, in minutes, to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
	DefaultAutoArchiveDuration int `json:"default_auto_archive_duration"`
	// Permissions computed permissions for the invoking user in the channel, including overwrites, only included when part of the `resolved` data received on a slash command interaction
	Permissions string `json:"permissions"`
}

type ChannelMention

type ChannelMention struct {
	// Id id of the channel
	Id string `json:"id"`
	// GuildId id of the guild containing the channel
	GuildId string `json:"guild_id"`
	// Type the [type of channel](#DOCS_RESOURCES_CHANNEL/channel-object-channel-types)
	Type int `json:"type"`
	// Name the name of the channel
	Name string `json:"name"`
}

type ChannelPinsUpdateEventData

type ChannelPinsUpdateEventData struct {
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// ChannelId the id of the channel
	ChannelId string `json:"channel_id"`
	// LastPinTimestamp the time at which the most recent pinned message was pinned
	LastPinTimestamp time.Time `json:"last_pin_timestamp"`
}

type ClientStatus

type ClientStatus struct {
	Desktop string `json:"desktop"`
	Mobile  string `json:"mobile"`
	Web     string `json:"web"`
}

ClientStatus Active sessions are indicated with an "online", "idle", or "dnd" string per platform. If a user is offline or invisible, the corresponding field is not present.

type Component

type Component struct {
	// Type [component type](#DOCS_INTERACTIONS_MESSAGE_COMPONENTS/component-object-component-types)
	Type int `json:"type"`
	// CustomId a developer-defined identifier for the component, max 100 characters
	CustomId string `json:"custom_id"`
	// Disabled whether the component is disabled, default `false`
	Disabled bool `json:"disabled"`
	// Style one of [button styles](#DOCS_INTERACTIONS_MESSAGE_COMPONENTS/button-object-button-styles)
	Style int `json:"style"`
	// Label text that appears on the button, max 80 characters
	Label string `json:"label"`
	// Emoji `name`, `id`, and `animated`
	Emoji Emoji `json:"emoji"`
	// Url a url for link-style buttons
	Url string `json:"url"`
	// Options the choices in the select, max 25
	Options []SelectOption `json:"options"`
	// Placeholder custom placeholder text if nothing is selected, max 100 characters
	Placeholder string `json:"placeholder"`
	// MinValues the minimum number of items that must be chosen; default 1, min 0, max 25
	MinValues int `json:"min_values"`
	// MaxValues the maximum number of items that can be chosen; default 1, max 25
	MaxValues int `json:"max_values"`
	// Components a list of child components
	Components []Component `json:"components"`
}

type Embed

type Embed struct {
	// Title title of embed
	Title string `json:"title"`
	// Type [type of embed](#DOCS_RESOURCES_CHANNEL/embed-object-embed-types) (always "rich" for webhook embeds)
	Type string `json:"type"`
	// Description description of embed
	Description string `json:"description"`
	// Url url of embed
	Url string `json:"url"`
	// Timestamp timestamp of embed content
	Timestamp time.Time `json:"timestamp"`
	// Color color code of the embed
	Color int `json:"color"`
	// Footer footer information
	Footer EmbedFooter `json:"footer"`
	// Image image information
	Image EmbedImage `json:"image"`
	// Thumbnail thumbnail information
	Thumbnail EmbedThumbnail `json:"thumbnail"`
	// Video video information
	Video EmbedVideo `json:"video"`
	// Provider provider information
	Provider EmbedProvider `json:"provider"`
	// Author author information
	Author EmbedAuthor `json:"author"`
	// Fields fields information
	Fields []EmbedField `json:"fields"`
}

type EmbedAuthor

type EmbedAuthor struct {
	// Name name of author
	Name string `json:"name"`
	// Url url of author
	Url string `json:"url"`
	// IconUrl url of author icon (only supports http(s) and attachments)
	IconUrl string `json:"icon_url"`
	// ProxyIconUrl a proxied url of author icon
	ProxyIconUrl string `json:"proxy_icon_url"`
}

type EmbedField

type EmbedField struct {
	// Name name of the field
	Name string `json:"name"`
	// Value value of the field
	Value string `json:"value"`
	// Inline whether or not this field should display inline
	Inline bool `json:"inline"`
}

type EmbedFooter

type EmbedFooter struct {
	// Text footer text
	Text string `json:"text"`
	// IconUrl url of footer icon (only supports http(s) and attachments)
	IconUrl string `json:"icon_url"`
	// ProxyIconUrl a proxied url of footer icon
	ProxyIconUrl string `json:"proxy_icon_url"`
}

type EmbedImage

type EmbedImage struct {
	// Url source url of image (only supports http(s) and attachments)
	Url string `json:"url"`
	// ProxyUrl a proxied url of the image
	ProxyUrl string `json:"proxy_url"`
	// Height height of image
	Height int `json:"height"`
	// Width width of image
	Width int `json:"width"`
}

type EmbedProvider

type EmbedProvider struct {
	// Name name of provider
	Name string `json:"name"`
	// Url url of provider
	Url string `json:"url"`
}

type EmbedThumbnail

type EmbedThumbnail struct {
	// Url source url of thumbnail (only supports http(s) and attachments)
	Url string `json:"url"`
	// ProxyUrl a proxied url of the thumbnail
	ProxyUrl string `json:"proxy_url"`
	// Height height of thumbnail
	Height int `json:"height"`
	// Width width of thumbnail
	Width int `json:"width"`
}

type EmbedVideo

type EmbedVideo struct {
	// Url source url of video
	Url string `json:"url"`
	// ProxyUrl a proxied url of the video
	ProxyUrl string `json:"proxy_url"`
	// Height height of video
	Height int `json:"height"`
	// Width width of video
	Width int `json:"width"`
}

type Emoji

type Emoji struct {
	// Id [emoji id](#DOCS_REFERENCE/image-formatting)
	Id string `json:"id"`
	// Name emoji name
	Name string `json:"name"`
	// Roles roles allowed to use this emoji
	Roles []string `json:"roles"`
	// User user that created this emoji
	User User `json:"user"`
	// RequireColons whether this emoji must be wrapped in colons
	RequireColons bool `json:"require_colons"`
	// Managed whether this emoji is managed
	Managed bool `json:"managed"`
	// Animated whether this emoji is animated
	Animated bool `json:"animated"`
	// Available whether this emoji can be used, may be false due to loss of Server Boosts
	Available bool `json:"available"`
}

type EventHandler

type EventHandler func(data interface{})

EventHandler is a function that takes a single interface{} argument which is an Event Data type as listed in events.go and documented in https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-events this is the expected argument for all event handlers, and is intentionally left as an interface{} type, instead of multiple handlers with concrete types. This prevents the need for a new handler each event message, and allows consumers of the library to use their own structs if desired. In order to reduce some code when converting to the desired

struct, the function DataToStruct is provided.

type Gateway

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

func NewGateway

func NewGateway(options ...GatewayOption) *Gateway

func (*Gateway) AddEventHandler

func (g *Gateway) AddEventHandler(eventType string, handler EventHandler)

AddEventHandlers adds and registers a function that will be called when the bot recieves a message for the specified event type. See EventHandler for the expected func, and DataToStruct on how to handle the function argument

func (*Gateway) Close

func (g *Gateway) Close() error

func (*Gateway) CloseWithCode

func (g *Gateway) CloseWithCode(code int) error

func (*Gateway) Start

func (g *Gateway) Start()

Start establishes and maintains websocket connection with the Discord Gateway

type GatewayConfig

type GatewayConfig struct {
	GatewayURL  string
	AuthToken   string
	ShardID     int
	TotalShards int
}

type GatewayOption

type GatewayOption func(g *Gateway)

func WithConfig

func WithConfig(config GatewayConfig) GatewayOption

func WithDialer

func WithDialer(d *websocket.Dialer) GatewayOption

WithDialer specifies a custom websocket.Dialer to use when connecting to the Discord Gateway

func WithLogger

func WithLogger(l Logger) GatewayOption

type GatewayPresenceUpdate

type GatewayPresenceUpdate struct {
	// Since unix time (in milliseconds) of when the client went idle, or null if the client is not idle
	Since int `json:"since"`
	// Activities the user's activities
	Activities []Activity `json:"activities"`
	// Status the user's new [status](#DOCS_TOPICS_GATEWAY/update-status-status-types)
	Status string `json:"status"`
	// Afk whether or not the client is afk
	Afk bool `json:"afk"`
}

type GatewayVoiceStateUpdate

type GatewayVoiceStateUpdate struct {
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// ChannelId id of the voice channel client wants to join (null if disconnecting)
	ChannelId string `json:"channel_id"`
	// SelfMute is the client muted
	SelfMute bool `json:"self_mute"`
	// SelfDeaf is the client deafened
	SelfDeaf bool `json:"self_deaf"`
}

type GetGatewayBotResponse

type GetGatewayBotResponse struct {
	// The WSS URL that can be used for connecting to the gateway
	Url string `json:"url"`
	// The recommended number of shards to use when connecting
	Shards int `json:"shards"`
	// Information on the current session start limit
	SessionStartLimit SessionStartLimit `json:"session_start_limit"`
}

type Guild

type Guild struct {
	// Id guild id
	Id string `json:"id"`
	// Name guild name (2-100 characters, excluding trailing and leading whitespace)
	Name string `json:"name"`
	// Icon [icon hash](#DOCS_REFERENCE/image-formatting)
	Icon string `json:"icon"`
	// IconHash [icon hash](#DOCS_REFERENCE/image-formatting), returned when in the template object
	IconHash string `json:"icon_hash"`
	// Splash [splash hash](#DOCS_REFERENCE/image-formatting)
	Splash string `json:"splash"`
	// DiscoverySplash [discovery splash hash](#DOCS_REFERENCE/image-formatting); only present for guilds with the "DISCOVERABLE" feature
	DiscoverySplash string `json:"discovery_splash"`
	// Owner true if [the user](#DOCS_RESOURCES_USER/get-current-user-guilds) is the owner of the guild
	Owner bool `json:"owner"`
	// OwnerId id of owner
	OwnerId string `json:"owner_id"`
	// Permissions total permissions for [the user](#DOCS_RESOURCES_USER/get-current-user-guilds) in the guild (excludes overwrites)
	Permissions string `json:"permissions"`
	// Region [voice region](#DOCS_RESOURCES_VOICE/voice-region-object) id for the guild (deprecated)
	Region string `json:"region"`
	// AfkChannelId id of afk channel
	AfkChannelId string `json:"afk_channel_id"`
	// AfkTimeout afk timeout in seconds
	AfkTimeout int `json:"afk_timeout"`
	// WidgetEnabled true if the server widget is enabled
	WidgetEnabled bool `json:"widget_enabled"`
	// WidgetChannelId the channel id that the widget will generate an invite to, or `null` if set to no invite
	WidgetChannelId string `json:"widget_channel_id"`
	// VerificationLevel [verification level](#DOCS_RESOURCES_GUILD/guild-object-verification-level) required for the guild
	VerificationLevel int `json:"verification_level"`
	// DefaultMessageNotifications default [message notifications level](#DOCS_RESOURCES_GUILD/guild-object-default-message-notification-level)
	DefaultMessageNotifications int `json:"default_message_notifications"`
	// ExplicitContentFilter [explicit content filter level](#DOCS_RESOURCES_GUILD/guild-object-explicit-content-filter-level)
	ExplicitContentFilter int `json:"explicit_content_filter"`
	// Roles roles in the guild
	Roles []Role `json:"roles"`
	// Emojis custom guild emojis
	Emojis []Emoji `json:"emojis"`
	// Features enabled guild features
	Features []string `json:"features"`
	// MfaLevel required [MFA level](#DOCS_RESOURCES_GUILD/guild-object-mfa-level) for the guild
	MfaLevel int `json:"mfa_level"`
	// ApplicationId application id of the guild creator if it is bot-created
	ApplicationId string `json:"application_id"`
	// SystemChannelId the id of the channel where guild notices such as welcome messages and boost events are posted
	SystemChannelId string `json:"system_channel_id"`
	// SystemChannelFlags [system channel flags](#DOCS_RESOURCES_GUILD/guild-object-system-channel-flags)
	SystemChannelFlags int `json:"system_channel_flags"`
	// RulesChannelId the id of the channel where Community guilds can display rules and/or guidelines
	RulesChannelId string `json:"rules_channel_id"`
	// JoinedAt when this guild was joined at
	JoinedAt time.Time `json:"joined_at"`
	// Large true if this is considered a large guild
	Large bool `json:"large"`
	// Unavailable true if this guild is unavailable due to an outage
	Unavailable bool `json:"unavailable"`
	// MemberCount total number of members in this guild
	MemberCount int `json:"member_count"`
	// VoiceStates states of members currently in voice channels; lacks the `guild_id` key
	VoiceStates []VoiceState `json:"voice_states"`
	// Members users in the guild
	Members []GuildMember `json:"members"`
	// Channels channels in the guild
	Channels []Channel `json:"channels"`
	// Threads all active threads in the guild that current user has permission to view
	Threads []Channel `json:"threads"`
	// Presences presences of the members in the guild, will only include non-offline members if the size is greater than `large threshold`
	Presences []PresenceUpdateEventData `json:"presences"`
	// MaxPresences the maximum number of presences for the guild (`null` is always returned, apart from the largest of guilds)
	MaxPresences int `json:"max_presences"`
	// MaxMembers the maximum number of members for the guild
	MaxMembers int `json:"max_members"`
	// VanityUrlCode the vanity url code for the guild
	VanityUrlCode string `json:"vanity_url_code"`
	// Description the description of a Community guild
	Description string `json:"description"`
	// Banner [banner hash](#DOCS_REFERENCE/image-formatting)
	Banner string `json:"banner"`
	// PremiumTier [premium tier](#DOCS_RESOURCES_GUILD/guild-object-premium-tier) (Server Boost level)
	PremiumTier int `json:"premium_tier"`
	// PremiumSubscriptionCount the number of boosts this guild currently has
	PremiumSubscriptionCount int `json:"premium_subscription_count"`
	// PreferredLocale the preferred locale of a Community guild; used in server discovery and notices from Discord; defaults to "en-US"
	PreferredLocale string `json:"preferred_locale"`
	// PublicUpdatesChannelId the id of the channel where admins and moderators of Community guilds receive notices from Discord
	PublicUpdatesChannelId string `json:"public_updates_channel_id"`
	// MaxVideoChannelUsers the maximum amount of users in a video channel
	MaxVideoChannelUsers int `json:"max_video_channel_users"`
	// ApproximateMemberCount approximate number of members in this guild, returned from the `GET /guilds/<id>` endpoint when `with_counts` is `true`
	ApproximateMemberCount int `json:"approximate_member_count"`
	// ApproximatePresenceCount approximate number of non-offline members in this guild, returned from the `GET /guilds/<id>` endpoint when `with_counts` is `true`
	ApproximatePresenceCount int `json:"approximate_presence_count"`
	// WelcomeScreen the welcome screen of a Community guild, shown to new members, returned in an [Invite](#DOCS_RESOURCES_INVITE/invite-object)'s guild object
	WelcomeScreen WelcomeScreen `json:"welcome_screen"`
	// NsfwLevel [guild NSFW level](#DOCS_RESOURCES_GUILD/guild-object-guild-nsfw-level)
	NsfwLevel int `json:"nsfw_level"`
	// StageInstances Stage instances in the guild
	StageInstances []StageInstance `json:"stage_instances"`
	// Stickers custom guild stickers
	Stickers []Sticker `json:"stickers"`
}

type GuildBanAddEventData

type GuildBanAddEventData struct {
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// User the banned user
	User User `json:"user"`
}

type GuildBanRemoveEventData

type GuildBanRemoveEventData struct {
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// User the unbanned user
	User User `json:"user"`
}

type GuildEmojisUpdateEventData

type GuildEmojisUpdateEventData struct {
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// Emojis array of [emojis](#DOCS_RESOURCES_EMOJI/emoji-object)
	Emojis []Emoji `json:"emojis"`
}

type GuildIntegrationsUpdateEventData

type GuildIntegrationsUpdateEventData struct {
	// GuildId id of the guild whose integrations were updated
	GuildId string `json:"guild_id"`
}

type GuildMember

type GuildMember struct {
	// User the user this guild member represents
	User User `json:"user"`
	// Nick this users guild nickname
	Nick string `json:"nick"`
	// Roles array of [role](#DOCS_TOPICS_PERMISSIONS/role-object) object ids
	Roles []string `json:"roles"`
	// JoinedAt when the user joined the guild
	JoinedAt time.Time `json:"joined_at"`
	// PremiumSince when the user started [boosting](https://support.discord.com/hc/en-us/articles/360028038352-Server-Boosting-) the guild
	PremiumSince time.Time `json:"premium_since"`
	// Deaf whether the user is deafened in voice channels
	Deaf bool `json:"deaf"`
	// Mute whether the user is muted in voice channels
	Mute bool `json:"mute"`
	// Pending whether the user has not yet passed the guild's [Membership Screening](#DOCS_RESOURCES_GUILD/membership-screening-object) requirements
	Pending bool `json:"pending"`
	// Permissions total permissions of the member in the channel, including overwrites, returned when in the interaction object
	Permissions string `json:"permissions"`
}

type GuildMemberRemoveEventData

type GuildMemberRemoveEventData struct {
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// User the user who was removed
	User User `json:"user"`
}

type GuildMemberUpdateEventData

type GuildMemberUpdateEventData struct {
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// Roles user role ids
	Roles []string `json:"roles"`
	// User the user
	User User `json:"user"`
	// Nick nickname of the user in the guild
	Nick string `json:"nick"`
	// JoinedAt when the user joined the guild
	JoinedAt time.Time `json:"joined_at"`
	// PremiumSince when the user starting [boosting](https://support.discord.com/hc/en-us/articles/360028038352-Server-Boosting-) the guild
	PremiumSince time.Time `json:"premium_since"`
	// Deaf whether the user is deafened in voice channels
	Deaf bool `json:"deaf"`
	// Mute whether the user is muted in voice channels
	Mute bool `json:"mute"`
	// Pending whether the user has not yet passed the guild's [Membership Screening](#DOCS_RESOURCES_GUILD/membership-screening-object) requirements
	Pending bool `json:"pending"`
}

type GuildMembersChunkEventData

type GuildMembersChunkEventData struct {
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// Members set of guild members
	Members []GuildMember `json:"members"`
	// ChunkIndex the chunk index in the expected chunks for this response (0 <= chunk\_index < chunk\_count)
	ChunkIndex int `json:"chunk_index"`
	// ChunkCount the total number of expected chunks for this response
	ChunkCount int `json:"chunk_count"`
	// NotFound if passing an invalid id to `REQUEST_GUILD_MEMBERS`, it will be returned here
	NotFound []string `json:"not_found"`
	// Presences if passing true to `REQUEST_GUILD_MEMBERS`, presences of the returned members will be here
	Presences []PresenceUpdateEventData `json:"presences"`
	// Nonce the nonce used in the [Guild Members Request](#DOCS_TOPICS_GATEWAY/request-guild-members)
	Nonce string `json:"nonce"`
}

type GuildRequestMembers

type GuildRequestMembers struct {
	// GuildId id of the guild to get members for
	GuildId string `json:"guild_id"`
	// Query string that username starts with, or an empty string to return all members
	Query string `json:"query"`
	// Limit maximum number of members to send matching the `query`; a limit of `0` can be used with an empty string `query` to return all members
	Limit int `json:"limit"`
	// Presences used to specify if we want the presences of the matched members
	Presences bool `json:"presences"`
	// UserIds used to specify which users you wish to fetch
	UserIds string `json:"user_ids"`
	// Nonce nonce to identify the [Guild Members Chunk](#DOCS_TOPICS_GATEWAY/guild-members-chunk) response
	Nonce string `json:"nonce"`
}

type GuildRoleCreateEventData

type GuildRoleCreateEventData struct {
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// Role the role created
	Role Role `json:"role"`
}

type GuildRoleDeleteEventData

type GuildRoleDeleteEventData struct {
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// RoleId id of the role
	RoleId string `json:"role_id"`
}

type GuildRoleUpdateEventData

type GuildRoleUpdateEventData struct {
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// Role the role updated
	Role Role `json:"role"`
}

type GuildStickersUpdateEventData

type GuildStickersUpdateEventData struct {
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// Stickers array of [stickers](#DOCS_RESOURCES_STICKER/sticker-object)
	Stickers []Sticker `json:"stickers"`
}

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type Hello

type Hello struct {
	// HeartbeatInterval the interval (in milliseconds) the client should heartbeat with
	HeartbeatInterval int `json:"heartbeat_interval"`
}

type Identify

type Identify struct {
	// Token authentication token
	Token string `json:"token"`
	// Properties [connection properties](#DOCS_TOPICS_GATEWAY/identify-identify-connection-properties)
	Properties IdentifyConnectionProperties `json:"properties"`
	// Compress whether this connection supports compression of packets
	Compress bool `json:"compress"`
	// LargeThreshold value between 50 and 250, total number of members where the gateway will stop sending offline members in the guild member list
	LargeThreshold int `json:"large_threshold"`
	// Shard used for [Guild Sharding](#DOCS_TOPICS_GATEWAY/sharding)
	Shard []int `json:"shard"`
	// Presence presence structure for initial presence information
	Presence PresenceUpdateEventData `json:"presence"`
	// Intents the [Gateway Intents](#DOCS_TOPICS_GATEWAY/gateway-intents) you wish to receive
	Intents int `json:"intents"`
}

type IdentifyConnectionProperties

type IdentifyConnectionProperties struct {
	OS      string `json:"$os"`
	Browser string `json:"$browser"`
	Device  string `json:"$device"`
}

type IntegrationDeleteEventData

type IntegrationDeleteEventData struct {
	// Id integration id
	Id string `json:"id"`
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// ApplicationId id of the bot/OAuth2 application for this discord integration
	ApplicationId string `json:"application_id"`
}

type InteractionApplicationCommandCallbackData

type InteractionApplicationCommandCallbackData struct {
	// Tts is the response TTS
	Tts bool `json:"tts"`
	// Content message content
	Content string `json:"content"`
	// Embeds supports up to 10 embeds
	Embeds []Embed `json:"embeds"`
	// AllowedMentions [allowed mentions](#DOCS_RESOURCES_CHANNEL/allowed-mentions-object) object
	AllowedMentions AllowedMentions `json:"allowed_mentions"`
	// Flags [interaction application command callback data flags](#DOCS_INTERACTIONS_SLASH_COMMANDS/interaction-response-object-interaction-application-command-callback-data-flags)
	Flags int `json:"flags"`
	// Components message components
	Components []Component `json:"components"`
}

type InteractionCallbackType

type InteractionCallbackType int
const (
	InteractionCallbackPong                             InteractionCallbackType = 1
	InteractionCallbackChannelMessageWithSource         InteractionCallbackType = 4
	InteractionCallbackDeferredChannelMessageWithSource InteractionCallbackType = 5
	InteractionCallbackDeferredUpdateMessage            InteractionCallbackType = 6
	InteractionCallbackUpdateMessage                    InteractionCallbackType = 7
)

type InteractionResponse

type InteractionResponse struct {
	// Type the type of response
	Type InteractionCallbackType `json:"type"`
	// Data an optional response message
	Data InteractionApplicationCommandCallbackData `json:"data"`
}

type InviteCreateEventData

type InviteCreateEventData struct {
	// ChannelId the channel the invite is for
	ChannelId string `json:"channel_id"`
	// Code the unique invite [code](#DOCS_RESOURCES_INVITE/invite-object)
	Code string `json:"code"`
	// CreatedAt the time at which the invite was created
	CreatedAt time.Time `json:"created_at"`
	// GuildId the guild of the invite
	GuildId string `json:"guild_id"`
	// Inviter the user that created the invite
	Inviter User `json:"inviter"`
	// MaxAge how long the invite is valid for (in seconds)
	MaxAge int `json:"max_age"`
	// MaxUses the maximum number of times the invite can be used
	MaxUses int `json:"max_uses"`
	// TargetType the [type of target](#DOCS_RESOURCES_INVITE/invite-object-invite-target-types) for this voice channel invite
	TargetType int `json:"target_type"`
	// TargetUser the user whose stream to display for this voice channel stream invite
	TargetUser User `json:"target_user"`
	// TargetApplication the embedded application to open for this voice channel embedded application invite
	TargetApplication Application `json:"target_application"`
	// Temporary whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role)
	Temporary bool `json:"temporary"`
	// Uses how many times the invite has been used (always will be 0)
	Uses int `json:"uses"`
}

type InviteDeleteEventData

type InviteDeleteEventData struct {
	// ChannelId the channel of the invite
	ChannelId string `json:"channel_id"`
	// GuildId the guild of the invite
	GuildId string `json:"guild_id"`
	// Code the unique invite [code](#DOCS_RESOURCES_INVITE/invite-object)
	Code string `json:"code"`
}

type Logger

type Logger interface {
	Debug(...interface{})
	Debugf(string, ...interface{})
	Info(...interface{})
	Infof(string, ...interface{})
	Error(...interface{})
	Errorf(string, ...interface{})
}

type Message

type Message struct {
	// Id id of the message
	Id string `json:"id"`
	// ChannelId id of the channel the message was sent in
	ChannelId string `json:"channel_id"`
	// GuildId id of the guild the message was sent in
	GuildId string `json:"guild_id"`
	// Author the author of this message (not guaranteed to be a valid user, see below)
	Author User `json:"author"`
	// Member member properties for this message's author
	Member GuildMember `json:"member"`
	// Content contents of the message
	Content string `json:"content"`
	// Timestamp when this message was sent
	Timestamp time.Time `json:"timestamp"`
	// EditedTimestamp when this message was edited (or null if never)
	EditedTimestamp time.Time `json:"edited_timestamp"`
	// Tts whether this was a TTS message
	Tts bool `json:"tts"`
	// MentionEveryone whether this message mentions everyone
	MentionEveryone bool `json:"mention_everyone"`
	// Mentions users specifically mentioned in the message
	Mentions []User `json:"mentions"`
	// MentionRoles roles specifically mentioned in this message
	MentionRoles []string `json:"mention_roles"`
	// MentionChannels channels specifically mentioned in this message
	MentionChannels []ChannelMention `json:"mention_channels"`
	// Attachments any attached files
	Attachments []Attachment `json:"attachments"`
	// Embeds any embedded content
	Embeds []Embed `json:"embeds"`
	// Reactions reactions to the message
	Reactions []Reaction `json:"reactions"`
	// Nonce used for validating a message was sent
	Nonce string `json:"nonce"`
	// Pinned whether this message is pinned
	Pinned bool `json:"pinned"`
	// WebhookId if the message is generated by a webhook, this is the webhook's id
	WebhookId string `json:"webhook_id"`
	// Type [type of message](#DOCS_RESOURCES_CHANNEL/message-object-message-types)
	Type int `json:"type"`
	// Activity sent with Rich Presence-related chat embeds
	Activity MessageActivity `json:"activity"`
	// Application sent with Rich Presence-related chat embeds
	Application Application `json:"application"`
	// ApplicationId if the message is a response to an [Interaction](#DOCS_INTERACTIONS_SLASH_COMMANDS/), this is the id of the interaction's application
	ApplicationId string `json:"application_id"`
	// MessageReference data showing the source of a crosspost, channel follow add, pin, or reply message
	MessageReference MessageReference `json:"message_reference"`
	// Flags [message flags](#DOCS_RESOURCES_CHANNEL/message-object-message-flags) combined as a [bitfield](https://en.wikipedia.org/wiki/Bit_field)
	Flags int `json:"flags"`
	// ReferencedMessage the message associated with the message_reference
	ReferencedMessage *Message `json:"referenced_message"`
	// Interaction sent if the message is a response to an [Interaction](#DOCS_INTERACTIONS_SLASH_COMMANDS/)
	Interaction InteractionResponse `json:"interaction"`
	// Thread the thread that was started from this message, includes [thread member](#DOCS_RESOURCES_CHANNEL/thread-member-object) object
	Thread Channel `json:"thread"`
	// Components sent if the message contains components like buttons, action rows, or other interactive components
	Components []Component `json:"components"`
	// StickerItems sent if the message contains stickers
	StickerItems []StickerItem `json:"sticker_items"`
	// Stickers **Deprecated** the stickers sent with the message
	Stickers []Sticker `json:"stickers"`
}

type MessageActivity

type MessageActivity struct {
	// Type [type of message activity](#DOCS_RESOURCES_CHANNEL/message-object-message-activity-types)
	Type int `json:"type"`
	// PartyId party_id from a [Rich Presence event](#DOCS_RICH_PRESENCE_HOW_TO/updating-presence-update-presence-payload-fields)
	PartyId string `json:"party_id"`
}

type MessageCreateEventData

type MessageCreateEventData struct {
	Message
}

type MessageDeleteBulkEventData

type MessageDeleteBulkEventData struct {
	// Ids the ids of the messages
	Ids []string `json:"ids"`
	// ChannelId the id of the channel
	ChannelId string `json:"channel_id"`
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
}

type MessageDeleteEventData

type MessageDeleteEventData struct {
	// Id the id of the message
	Id string `json:"id"`
	// ChannelId the id of the channel
	ChannelId string `json:"channel_id"`
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
}

type MessageReactionAddEventData

type MessageReactionAddEventData struct {
	// UserId the id of the user
	UserId string `json:"user_id"`
	// ChannelId the id of the channel
	ChannelId string `json:"channel_id"`
	// MessageId the id of the message
	MessageId string `json:"message_id"`
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// Member the member who reacted if this happened in a guild
	Member GuildMember `json:"member"`
	// Emoji the emoji used to react - [example](#DOCS_RESOURCES_EMOJI/emoji-object-gateway-reaction-standard-emoji-example)
	Emoji Emoji `json:"emoji"`
}

type MessageReactionRemoveAllEventData

type MessageReactionRemoveAllEventData struct {
	// ChannelId the id of the channel
	ChannelId string `json:"channel_id"`
	// MessageId the id of the message
	MessageId string `json:"message_id"`
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
}

type MessageReactionRemoveEventData

type MessageReactionRemoveEventData struct {
	// UserId the id of the user
	UserId string `json:"user_id"`
	// ChannelId the id of the channel
	ChannelId string `json:"channel_id"`
	// MessageId the id of the message
	MessageId string `json:"message_id"`
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// Emoji the emoji used to react - [example](#DOCS_RESOURCES_EMOJI/emoji-object-gateway-reaction-standard-emoji-example)
	Emoji Emoji `json:"emoji"`
}

type MessageReference

type MessageReference struct {
	// MessageId id of the originating message
	MessageId string `json:"message_id"`
	// ChannelId id of the originating message's channel
	ChannelId string `json:"channel_id"`
	// GuildId id of the originating message's guild
	GuildId string `json:"guild_id"`
	// FailIfNotExists when sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true
	FailIfNotExists bool `json:"fail_if_not_exists"`
}

type MessageUpdateEventData

type MessageUpdateEventData struct {
	Message
}

type Overwrite

type Overwrite struct {
	// Id role or user id
	Id string `json:"id"`
	// Type either 0 (role) or 1 (member)
	Type int `json:"type"`
	// Allow permission bit set
	Allow string `json:"allow"`
	// Deny permission bit set
	Deny string `json:"deny"`
}

type Payload

type Payload struct {
	// Op [opcode](#DOCS_TOPICS_OPCODES_AND_STATUS_CODES/gateway-opcodes) for the payload
	Op int `json:"op"`
	// D event data
	D interface{} `json:"d"`
	// S sequence number, used for resuming sessions and heartbeats
	S int `json:"s"`
	// T the event name for this payload
	T string `json:"t"`
}

func (*Payload) MarshalData

func (p *Payload) MarshalData(v interface{}) error

MarshalData marshals the payload D to a provided struct value. v should always be a pointer to a target value

type PresenceUpdateEventData

type PresenceUpdateEventData struct {
	// User the user presence is being updated for
	User User `json:"user"`
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// Status either "idle", "dnd", "online", or "offline"
	Status string `json:"status"`
	// Activities user's current activities
	Activities []Activity `json:"activities"`
	// ClientStatus user's platform-dependent status
	ClientStatus ClientStatus `json:"client_status"`
}

type Reaction

type Reaction struct {
	// Count times this emoji has been used to react
	Count int `json:"count"`
	// Me whether the current user reacted using this emoji
	Me bool `json:"me"`
	// Emoji emoji information
	Emoji Emoji `json:"emoji"`
}

type ReadyEventData

type ReadyEventData struct {
	// V [gateway version](#DOCS_TOPICS_GATEWAY/gateways-gateway-versions)
	V int `json:"v"`
	// User information about the user including email
	User User `json:"user"`
	// Guilds the guilds the user is in
	Guilds []Guild `json:"guilds"`
	// SessionId used for resuming connections
	SessionId string `json:"session_id"`
	// Shard the [shard information](#DOCS_TOPICS_GATEWAY/sharding) associated with this session, if sent when identifying
	Shard []int `json:"shard"`
	// Application contains `id` and `flags`
	Application Application `json:"application"`
}

type Resume

type Resume struct {
	// Token session token
	Token string `json:"token"`
	// SessionId session id
	SessionId string `json:"session_id"`
	// Seq last sequence number received
	Seq int `json:"seq"`
}

type Role

type Role struct {
	// Id role id
	Id string `json:"id"`
	// Name role name
	Name string `json:"name"`
	// Color integer representation of hexadecimal color code
	Color int `json:"color"`
	// Hoist if this role is pinned in the user listing
	Hoist bool `json:"hoist"`
	// Position position of this role
	Position int `json:"position"`
	// Permissions permission bit set
	Permissions string `json:"permissions"`
	// Managed whether this role is managed by an integration
	Managed bool `json:"managed"`
	// Mentionable whether this role is mentionable
	Mentionable bool `json:"mentionable"`
	// Tags the tags this role has
	Tags RoleTags `json:"tags"`
}

type RoleTags

type RoleTags struct {
	// BotId the id of the bot this role belongs to
	BotId string `json:"bot_id"`
	// IntegrationId the id of the integration this role belongs to
	IntegrationId string `json:"integration_id"`
	// PremiumSubscriber whether this is the guild's premium subscriber role
	PremiumSubscriber interface{} `json:"premium_subscriber"`
}

type SelectOption

type SelectOption struct {
	// Label the user-facing name of the option, max 25 characters
	Label string `json:"label"`
	// Value the dev-define value of the option, max 100 characters
	Value string `json:"value"`
	// Description an additional description of the option, max 50 characters
	Description string `json:"description"`
	// Emoji `id`, `name`, and `animated`
	Emoji Emoji `json:"emoji"`
	// Default will render this option as selected by default
	Default bool `json:"default"`
}

type SessionStartLimit

type SessionStartLimit struct {
	// Total The total number of session starts the current user is allowed
	Total int `json:"total"`
	// Remaining The remaining number of session starts the current user is allowed
	Remaining int `json:"remaining"`
	// ResetAfter The number of milliseconds after which the limit resets
	ResetAfter int `json:"reset_after"`
	// MaxConcurrency The number of identify requests allowed per 5 seconds
	MaxConcurrency int `json:"max_concurrency"`
}

type StageInstance

type StageInstance struct {
	// Id The id of this Stage instance
	Id string `json:"id"`
	// GuildId The guild id of the associated Stage channel
	GuildId string `json:"guild_id"`
	// ChannelId The id of the associated Stage channel
	ChannelId string `json:"channel_id"`
	// Topic The topic of the Stage instance (1-120 characters)
	Topic string `json:"topic"`
	// PrivacyLevel The [privacy level](#DOCS_RESOURCES_STAGE_INSTANCE/stage-instance-object-privacy-level) of the Stage instance
	PrivacyLevel int `json:"privacy_level"`
	// DiscoverableDisabled Whether or not Stage Discovery is disabled
	DiscoverableDisabled bool `json:"discoverable_disabled"`
}

type Sticker

type Sticker struct {
	// Id [id of the sticker](#DOCS_REFERENCE/image-formatting)
	Id string `json:"id"`
	// PackId for standard stickers, id of the pack the sticker is from
	PackId string `json:"pack_id"`
	// Name name of the sticker
	Name string `json:"name"`
	// Description description of the sticker
	Description string `json:"description"`
	// Tags for guild stickers, the Discord name of a unicode emoji representing the sticker's expression. for standard stickers, a comma-separated list of related expressions.
	Tags string `json:"tags"`
	// Asset **Deprecated** previously the sticker asset hash, now an empty string
	Asset string `json:"asset"`
	// Type [type of sticker](#DOCS_RESOURCES_STICKER/sticker-object-sticker-types)
	Type int `json:"type"`
	// FormatType [type of sticker format](#DOCS_RESOURCES_STICKER/sticker-object-sticker-format-types)
	FormatType int `json:"format_type"`
	// Available whether this guild sticker can be used, may be false due to loss of Server Boosts
	Available bool `json:"available"`
	// GuildId id of the guild that owns this sticker
	GuildId string `json:"guild_id"`
	// User the user that uploaded the guild sticker
	User User `json:"user"`
	// SortValue the standard sticker's sort order within its pack
	SortValue int `json:"sort_value"`
}

type StickerItem

type StickerItem struct {
	// Id id of the sticker
	Id string `json:"id"`
	// Name name of the sticker
	Name string `json:"name"`
	// FormatType [type of sticker format](#DOCS_RESOURCES_STICKER/sticker-object-sticker-format-types)
	FormatType int `json:"format_type"`
}

type Team

type Team struct {
	// Icon a hash of the image of the team's icon
	Icon string `json:"icon"`
	// Id the unique id of the team
	Id string `json:"id"`
	// Members the members of the team
	Members []TeamMember `json:"members"`
	// Name the name of the team
	Name string `json:"name"`
	// OwnerUserId the user id of the current team owner
	OwnerUserId string `json:"owner_user_id"`
}

type TeamMember

type TeamMember struct {
	// MembershipState the user's [membership state](#DOCS_TOPICS_TEAMS/data-models-membership-state-enum) on the team
	MembershipState int `json:"membership_state"`
	// Permissions will always be `["*"]`
	Permissions []string `json:"permissions"`
	// TeamId the id of the parent team of which they are a member
	TeamId string `json:"team_id"`
	// User the avatar, discriminator, id, and username of the user
	User User `json:"user"`
}

type ThreadListSyncEventData

type ThreadListSyncEventData struct {
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// ChannelIds the parent channel ids whose threads are being synced.  If omitted, then threads were synced for the entire guild.  This array may contain channel_ids that have no active threads as well, so you know to clear that data.
	ChannelIds []string `json:"channel_ids"`
	// Threads all active threads in the given channels that the current user can access
	Threads []Channel `json:"threads"`
	// Members all thread member objects from the synced threads for the current user, indicating which threads the current user has been added to
	Members []ThreadMember `json:"members"`
}

type ThreadMember

type ThreadMember struct {
	// Id the id of the thread
	Id string `json:"id"`
	// UserId the id of the user
	UserId string `json:"user_id"`
	// JoinTimestamp the time the current user last joined the thread
	JoinTimestamp time.Time `json:"join_timestamp"`
	// Flags any user-thread settings, currently only used for notifications
	Flags int `json:"flags"`
}

type ThreadMembersUpdateEventData

type ThreadMembersUpdateEventData struct {
	// Id the id of the thread
	Id string `json:"id"`
	// GuildId the id of the guild
	GuildId string `json:"guild_id"`
	// MemberCount the approximate number of members in the thread, capped at 50
	MemberCount int `json:"member_count"`
	// AddedMembers the users who were added to the thread
	AddedMembers []ThreadMember `json:"added_members"`
	// RemovedMemberIds the id of the users who were removed from the thread
	RemovedMemberIds []string `json:"removed_member_ids"`
}

type ThreadMetadata

type ThreadMetadata struct {
	// Archived whether the thread is archived
	Archived bool `json:"archived"`
	// AutoArchiveDuration duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
	AutoArchiveDuration int `json:"auto_archive_duration"`
	// ArchiveTimestamp timestamp when the thread's archive status was last changed, used for calculating recent activity
	ArchiveTimestamp time.Time `json:"archive_timestamp"`
	// Locked whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
	Locked bool `json:"locked"`
}

type TypingStartEventData

type TypingStartEventData struct {
	// ChannelId id of the channel
	ChannelId string `json:"channel_id"`
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// UserId id of the user
	UserId string `json:"user_id"`
	// Timestamp unix time (in seconds) of when the user started typing
	Timestamp int `json:"timestamp"`
	// Member the member who started typing if this happened in a guild
	Member GuildMember `json:"member"`
}

type User

type User struct {
	// Id the user's id
	Id string `json:"id"`
	// Username the user's username, not unique across the platform
	Username string `json:"username"`
	// Discriminator the user's 4-digit discord-tag
	Discriminator string `json:"discriminator"`
	// Avatar the user's [avatar hash](#DOCS_REFERENCE/image-formatting)
	Avatar string `json:"avatar"`
	// Bot whether the user belongs to an OAuth2 application
	Bot bool `json:"bot"`
	// System whether the user is an Official Discord System user (part of the urgent message system)
	System bool `json:"system"`
	// MfaEnabled whether the user has two factor enabled on their account
	MfaEnabled bool `json:"mfa_enabled"`
	// Locale the user's chosen language option
	Locale string `json:"locale"`
	// Verified whether the email on this account has been verified
	Verified bool `json:"verified"`
	// Email the user's email
	Email string `json:"email"`
	// Flags the [flags](#DOCS_RESOURCES_USER/user-object-user-flags) on a user's account
	Flags int `json:"flags"`
	// PremiumType the [type of Nitro subscription](#DOCS_RESOURCES_USER/user-object-premium-types) on a user's account
	PremiumType int `json:"premium_type"`
	// PublicFlags the public [flags](#DOCS_RESOURCES_USER/user-object-user-flags) on a user's account
	PublicFlags int `json:"public_flags"`
	// Member only included with partial data for some guild based purposes
	Member *GuildMember `json:"member,omitempty"`
}

type VoiceServerUpdateEventData

type VoiceServerUpdateEventData struct {
	// Token voice connection token
	Token string `json:"token"`
	// GuildId the guild this voice server update is for
	GuildId string `json:"guild_id"`
	// Endpoint the voice server host
	Endpoint string `json:"endpoint"`
}

type VoiceState

type VoiceState struct {
	// GuildId the guild id this voice state is for
	GuildId string `json:"guild_id"`
	// ChannelId the channel id this user is connected to
	ChannelId string `json:"channel_id"`
	// UserId the user id this voice state is for
	UserId string `json:"user_id"`
	// Member the guild member this voice state is for
	Member GuildMember `json:"member"`
	// SessionId the session id for this voice state
	SessionId string `json:"session_id"`
	// Deaf whether this user is deafened by the server
	Deaf bool `json:"deaf"`
	// Mute whether this user is muted by the server
	Mute bool `json:"mute"`
	// SelfDeaf whether this user is locally deafened
	SelfDeaf bool `json:"self_deaf"`
	// SelfMute whether this user is locally muted
	SelfMute bool `json:"self_mute"`
	// SelfStream whether this user is streaming using "Go Live"
	SelfStream bool `json:"self_stream"`
	// SelfVideo whether this user's camera is enabled
	SelfVideo bool `json:"self_video"`
	// Suppress whether this user is muted by the current user
	Suppress bool `json:"suppress"`
	// RequestToSpeakTimestamp the time at which the user requested to speak
	RequestToSpeakTimestamp time.Time `json:"request_to_speak_timestamp"`
}

type WebhookUpdateEventData

type WebhookUpdateEventData struct {
	// GuildId id of the guild
	GuildId string `json:"guild_id"`
	// ChannelId id of the channel
	ChannelId string `json:"channel_id"`
}

type WelcomeScreen

type WelcomeScreen struct {
	// Description the server description shown in the welcome screen
	Description string `json:"description"`
	// WelcomeChannels the channels shown in the welcome screen, up to 5
	WelcomeChannels []WelcomeScreenChannel `json:"welcome_channels"`
}

type WelcomeScreenChannel

type WelcomeScreenChannel struct {
	// ChannelId the channel's id
	ChannelId string `json:"channel_id"`
	// Description the description shown for the channel
	Description string `json:"description"`
	// EmojiId the [emoji id](#DOCS_REFERENCE/image-formatting), if the emoji is custom
	EmojiId string `json:"emoji_id"`
	// EmojiName the emoji name if custom, the unicode character if standard, or `null` if no emoji is set
	EmojiName string `json:"emoji_name"`
}

Directories

Path Synopsis
cmd
parseDocs Module
examples
gateway_bot Module

Jump to

Keyboard shortcuts

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