Version: v1.3.14 Latest Latest

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

Go to latest
Published: Nov 2, 2020 License: ISC Imports: 18 Imported by: 32



Package gateway handles the Discord gateway (or Websocket) connection, its events, and everything related to it. This includes logging into the Websocket.

This package does not abstract events and function handlers; instead, it leaves that to the session package. This package exposes only a single Events channel.



This section is empty.


View Source
var (
	EndpointGateway    = api.Endpoint + "gateway"
	EndpointGatewayBot = api.EndpointGateway + "/bot"

	Version  = "6"
	Encoding = "json"
View Source
var (
	ErrMissingForResume = errors.New("missing session ID or sequence for resuming")
	ErrWSMaxTries       = errors.New("max tries reached")
View Source
var ErrReconnectRequest = errors.New("ReconnectOP received")

ErrReconnectRequest is returned by HandleOP if a ReconnectOP is given. This is used mostly internally to signal the heartbeat loop to reconnect, if needed. It is not a fatal error.

View Source
var EventCreator = map[string]func() Event{
	"HELLO":           func() Event { return new(HelloEvent) },
	"READY":           func() Event { return new(ReadyEvent) },
	"RESUMED":         func() Event { return new(ResumedEvent) },
	"INVALID_SESSION": func() Event { return new(InvalidSessionEvent) },

	"CHANNEL_CREATE":        func() Event { return new(ChannelCreateEvent) },
	"CHANNEL_UPDATE":        func() Event { return new(ChannelUpdateEvent) },
	"CHANNEL_DELETE":        func() Event { return new(ChannelDeleteEvent) },
	"CHANNEL_PINS_UPDATE":   func() Event { return new(ChannelPinsUpdateEvent) },
	"CHANNEL_UNREAD_UPDATE": func() Event { return new(ChannelUnreadUpdateEvent) },

	"GUILD_CREATE": func() Event { return new(GuildCreateEvent) },
	"GUILD_UPDATE": func() Event { return new(GuildUpdateEvent) },
	"GUILD_DELETE": func() Event { return new(GuildDeleteEvent) },

	"GUILD_BAN_ADD":    func() Event { return new(GuildBanAddEvent) },
	"GUILD_BAN_REMOVE": func() Event { return new(GuildBanRemoveEvent) },

	"GUILD_EMOJIS_UPDATE":       func() Event { return new(GuildEmojisUpdateEvent) },
	"GUILD_INTEGRATIONS_UPDATE": func() Event { return new(GuildIntegrationsUpdateEvent) },

	"GUILD_MEMBER_ADD":    func() Event { return new(GuildMemberAddEvent) },
	"GUILD_MEMBER_REMOVE": func() Event { return new(GuildMemberRemoveEvent) },
	"GUILD_MEMBER_UPDATE": func() Event { return new(GuildMemberUpdateEvent) },
	"GUILD_MEMBERS_CHUNK": func() Event { return new(GuildMembersChunkEvent) },

	"GUILD_MEMBER_LIST_UPDATE": func() Event { return new(GuildMemberListUpdate) },

	"GUILD_ROLE_CREATE": func() Event { return new(GuildRoleCreateEvent) },
	"GUILD_ROLE_UPDATE": func() Event { return new(GuildRoleUpdateEvent) },
	"GUILD_ROLE_DELETE": func() Event { return new(GuildRoleDeleteEvent) },

	"INVITE_CREATE": func() Event { return new(InviteCreateEvent) },
	"INVITE_DELETE": func() Event { return new(InviteDeleteEvent) },

	"MESSAGE_CREATE":      func() Event { return new(MessageCreateEvent) },
	"MESSAGE_UPDATE":      func() Event { return new(MessageUpdateEvent) },
	"MESSAGE_DELETE":      func() Event { return new(MessageDeleteEvent) },
	"MESSAGE_DELETE_BULK": func() Event { return new(MessageDeleteBulkEvent) },

	"MESSAGE_REACTION_ADD":        func() Event { return new(MessageReactionAddEvent) },
	"MESSAGE_REACTION_REMOVE":     func() Event { return new(MessageReactionRemoveEvent) },
	"MESSAGE_REACTION_REMOVE_ALL": func() Event { return new(MessageReactionRemoveAllEvent) },

	"MESSAGE_ACK": func() Event { return new(MessageAckEvent) },

	"PRESENCE_UPDATE":   func() Event { return new(PresenceUpdateEvent) },
	"PRESENCES_REPLACE": func() Event { return new(PresencesReplaceEvent) },
	"SESSIONS_REPLACE":  func() Event { return new(SessionsReplaceEvent) },

	"TYPING_START": func() Event { return new(TypingStartEvent) },

	"VOICE_STATE_UPDATE":  func() Event { return new(VoiceStateUpdateEvent) },
	"VOICE_SERVER_UPDATE": func() Event { return new(VoiceServerUpdateEvent) },

	"WEBHOOKS_UPDATE": func() Event { return new(WebhooksUpdateEvent) },

	"USER_UPDATE":                func() Event { return new(UserUpdateEvent) },
	"USER_SETTINGS_UPDATE":       func() Event { return new(UserSettingsUpdateEvent) },
	"USER_GUILD_SETTINGS_UPDATE": func() Event { return new(UserGuildSettingsUpdateEvent) },
	"USER_NOTE_UPDATE":           func() Event { return new(UserNoteUpdateEvent) },

	"RELATIONSHIP_ADD":    func() Event { return new(RelationshipAddEvent) },
	"RELATIONSHIP_REMOVE": func() Event { return new(RelationshipRemoveEvent) },
View Source
var Identity = IdentifyProperties{
	OS:      runtime.GOOS,
	Browser: "Arikawa",
	Device:  "Arikawa",

Identity is used as the default identity when initializing a new Gateway.


func URL added in v0.4.0

func URL() (string, error)

URL asks Discord for a Websocket URL to the Gateway.


type BotData added in v1.0.0

type BotData struct {
	URL        string             `json:"url"`
	Shards     int                `json:"shards,omitempty"`
	StartLimit *SessionStartLimit `json:"session_start_limit"`

BotData contains the GatewayURL as well as extra metadata on how to shard bots.

func BotURL added in v0.4.0

func BotURL(token string) (*BotData, error)

BotURL fetches the Gateway URL along with extra metadata. The token passed in will NOT be prefixed with Bot.

type ChannelPinsUpdateEvent

type ChannelPinsUpdateEvent struct {
	GuildID   discord.GuildID   `json:"guild_id,omitempty"`
	ChannelID discord.ChannelID `json:"channel_id,omitempty"`
	LastPin   discord.Timestamp `json:"timestamp,omitempty"`

type ChannelUnreadUpdateEvent added in v0.1.4

type ChannelUnreadUpdateEvent struct {
	GuildID discord.GuildID `json:"guild_id"`

	ChannelUnreadUpdates []struct {
		ID            discord.ChannelID `json:"id"`
		LastMessageID discord.MessageID `json:"last_message_id"`

type Event

type Event = interface{}

Event is any event struct. They have an "Event" suffixed to them.

type Gateway

type Gateway struct {
	WS        *wsutil.Websocket
	WSTimeout time.Duration

	// All events sent over are pointers to Event structs (structs suffixed with
	// "Event"). This shouldn't be accessed if the Gateway is created with a
	// Session.
	Events chan Event

	// SessionID is used to store the session ID received after Ready. It is not
	// thread-safe.
	SessionID string

	Identifier *Identifier
	Sequence   *Sequence

	PacerLoop wsutil.PacemakerLoop

	ErrorLog func(err error) // default to log.Println

	// AfterClose is called after each close. Error can be non-nil, as this is
	// called even when the Gateway is gracefully closed. It's used mainly for
	// reconnections or any type of connection interruptions.
	AfterClose func(err error) // noop by default
	// contains filtered or unexported fields

func NewCustomGateway added in v0.3.2

func NewCustomGateway(gatewayURL, token string) *Gateway

func NewGateway

func NewGateway(token string) (*Gateway, error)

NewGateway creates a new Gateway with the default stdlib JSON driver. For more information, refer to NewGatewayWithDriver.

func NewGatewayWithIntents added in v0.10.0

func NewGatewayWithIntents(token string, intents ...Intents) (*Gateway, error)

NewGatewayWithIntents creates a new Gateway with the given intents and the default stdlib JSON driver. Refer to NewGatewayWithDriver and AddIntents.

func (*Gateway) AddIntent added in v0.10.0

func (g *Gateway) AddIntent(i Intents)

AddIntent adds a Gateway Intent before connecting to the Gateway. As such, this function will only work before Open() is called.

func (*Gateway) Close

func (g *Gateway) Close() error

Close closes the underlying Websocket connection.

func (*Gateway) GuildSubscribe

func (g *Gateway) GuildSubscribe(data GuildSubscribeData) error

func (*Gateway) GuildSubscribeCtx added in v0.10.0

func (g *Gateway) GuildSubscribeCtx(ctx context.Context, data GuildSubscribeData) error

func (*Gateway) HandleOP added in v0.5.0

func (g *Gateway) HandleOP(op *wsutil.OP) error

func (*Gateway) Heartbeat

func (g *Gateway) Heartbeat() error

func (*Gateway) HeartbeatCtx added in v0.10.0

func (g *Gateway) HeartbeatCtx(ctx context.Context) error

func (*Gateway) Identify

func (g *Gateway) Identify() error

func (*Gateway) IdentifyCtx added in v0.10.0

func (g *Gateway) IdentifyCtx(ctx context.Context) error

func (*Gateway) Open

func (g *Gateway) Open() error

Open connects to the Websocket and authenticate it. You should usually use this function over Start().

func (*Gateway) OpenContext added in v0.5.0

func (g *Gateway) OpenContext(ctx context.Context) error

OpenContext connects to the Websocket and authenticates it. You should usually use this function over Start(). The given context provides cancellation and timeout.

func (*Gateway) Reconnect

func (g *Gateway) Reconnect()

Reconnect tries to reconnect forever. It will resume the connection if possible. If an Invalid Session is received, it will start a fresh one.

func (*Gateway) ReconnectCtx added in v0.10.0

func (g *Gateway) ReconnectCtx(ctx context.Context) (err error)

ReconnectCtx attempts to reconnect until context expires. If context cannot expire, then the gateway will try to reconnect forever.

func (*Gateway) RequestGuildMembers

func (g *Gateway) RequestGuildMembers(data RequestGuildMembersData) error

func (*Gateway) RequestGuildMembersCtx added in v0.10.0

func (g *Gateway) RequestGuildMembersCtx(
	ctx context.Context, data RequestGuildMembersData) error

func (*Gateway) Resume

func (g *Gateway) Resume() error

Resume sends to the Websocket a Resume OP, but it doesn't actually resume from a dead connection. Start() resumes from a dead connection.

func (*Gateway) ResumeCtx added in v0.10.0

func (g *Gateway) ResumeCtx(ctx context.Context) error

ResumeCtx sends to the Websocket a Resume OP, but it doesn't actually resume from a dead connection. Start() resumes from a dead connection.

func (*Gateway) SendCtx added in v0.10.0

func (g *Gateway) SendCtx(ctx context.Context, code OPCode, v interface{}) error

SendCtx is a low-level function to send an OP payload to the Gateway. Most users shouldn't touch this, unless they know what they're doing.

func (*Gateway) Start

func (g *Gateway) Start() error

Start calls StartCtx with a background context. You wouldn't usually use this function, but Open() instead.

func (*Gateway) StartCtx added in v0.10.0

func (g *Gateway) StartCtx(ctx context.Context) error

StartCtx authenticates with the websocket, or resume from a dead Websocket connection. You wouldn't usually use this function, but OpenCtx() instead.

func (*Gateway) UpdateStatus

func (g *Gateway) UpdateStatus(data UpdateStatusData) error

func (*Gateway) UpdateStatusCtx added in v0.10.0

func (g *Gateway) UpdateStatusCtx(ctx context.Context, data UpdateStatusData) error

func (*Gateway) UpdateVoiceState

func (g *Gateway) UpdateVoiceState(data UpdateVoiceStateData) error

func (*Gateway) UpdateVoiceStateCtx added in v0.10.0

func (g *Gateway) UpdateVoiceStateCtx(
	ctx context.Context, data UpdateVoiceStateData) error

type GuildBanAddEvent

type GuildBanAddEvent struct {
	GuildID discord.GuildID `json:"guild_id"`
	User    discord.User    `json:"user"`

type GuildBanRemoveEvent

type GuildBanRemoveEvent struct {
	GuildID discord.GuildID `json:"guild_id"`
	User    discord.User    `json:"user"`

type GuildCreateEvent

type GuildCreateEvent struct {

	Joined      discord.Timestamp `json:"timestamp,omitempty"`
	Large       bool              `json:"large,omitempty"`
	Unavailable bool              `json:"unavailable,omitempty"`
	MemberCount uint64            `json:"member_count,omitempty"`

	VoiceStates []discord.VoiceState `json:"voice_states,omitempty"`
	Members     []discord.Member     `json:"members,omitempty"`
	Channels    []discord.Channel    `json:"channels,omitempty"`
	Presences   []discord.Presence   `json:"presences,omitempty"`

type GuildDeleteEvent

type GuildDeleteEvent struct {
	ID discord.GuildID `json:"id"`
	// Unavailable if false == removed
	Unavailable bool `json:"unavailable"`

type GuildEmojisUpdateEvent

type GuildEmojisUpdateEvent struct {
	GuildID discord.GuildID `json:"guild_id"`
	Emojis  []discord.Emoji `json:"emoji"`

type GuildFolder added in v0.0.2

type GuildFolder struct {
	Name     string            `json:"name"`
	ID       GuildFolderID     `json:"id"`
	GuildIDs []discord.GuildID `json:"guild_ids"`
	Color    discord.Color     `json:"color"`

GuildFolder holds a single folder that you see in the left guild panel.

type GuildFolderID added in v1.1.6

type GuildFolderID int64

GuildFolderID is possibly a snowflake. It can also be 0 (null) or a low number of unknown significance.

func (GuildFolderID) MarshalJSON added in v1.1.6

func (g GuildFolderID) MarshalJSON() ([]byte, error)

func (*GuildFolderID) UnmarshalJSON added in v1.1.6

func (g *GuildFolderID) UnmarshalJSON(b []byte) error

type GuildIntegrationsUpdateEvent

type GuildIntegrationsUpdateEvent struct {
	GuildID discord.GuildID `json:"guild_id"`

type GuildMemberAddEvent

type GuildMemberAddEvent struct {
	GuildID discord.GuildID `json:"guild_id"`

type GuildMemberListGroup added in v0.2.0

type GuildMemberListGroup struct {
	ID    string `json:"id"` // either discord.RoleID, "online" or "offline"
	Count uint64 `json:"count"`

type GuildMemberListOp added in v0.2.0

type GuildMemberListOp struct {
	// Mysterious string, so far spotted to be [SYNC, INSERT, UPDATE, DELETE].
	Op string `json:"op"`

	// Only available for Ops that aren't "SYNC".
	Index int                   `json:"index,omitempty"`
	Item  GuildMemberListOpItem `json:"item,omitempty"`

	// Range requested in GuildSubscribeData.
	Range [2]int `json:"range,omitempty"`
	// Items is basically a linear list of roles and members, similarly to
	// how the client renders it. No, it's not nested.
	Items []GuildMemberListOpItem `json:"items,omitempty"`

type GuildMemberListOpItem added in v0.2.0

type GuildMemberListOpItem struct {
	Group  *GuildMemberListGroup `json:"group,omitempty"`
	Member *struct {
		HoistedRole string           `json:"hoisted_role"`
		Presence    discord.Presence `json:"presence"`
	} `json:"member,omitempty"`

GuildMemberListOpItem is an enum. Either of the fields are provided, but never both. Refer to (*GuildMemberListUpdate).Ops for more.

type GuildMemberListUpdate added in v0.2.0

type GuildMemberListUpdate struct {
	ID          string          `json:"id"`
	GuildID     discord.GuildID `json:"guild_id"`
	MemberCount uint64          `json:"member_count"`
	OnlineCount uint64          `json:"online_count"`

	// Groups is all the visible role sections.
	Groups []GuildMemberListGroup `json:"groups"`

	Ops []GuildMemberListOp `json:"ops"`

GuildMemberListUpdate is an undocumented event. It's received when the client sends over GuildSubscriptions with the Channels field used. The State package does not handle this event.

type GuildMemberRemoveEvent

type GuildMemberRemoveEvent struct {
	GuildID discord.GuildID `json:"guild_id"`
	User    discord.User    `json:"user"`

type GuildMemberUpdateEvent

type GuildMemberUpdateEvent struct {
	GuildID discord.GuildID  `json:"guild_id"`
	RoleIDs []discord.RoleID `json:"roles"`
	User    discord.User     `json:"user"`
	Nick    string           `json:"nick"`

func (GuildMemberUpdateEvent) Update

func (u GuildMemberUpdateEvent) Update(m *discord.Member)

type GuildMembersChunkEvent

type GuildMembersChunkEvent struct {
	GuildID discord.GuildID  `json:"guild_id"`
	Members []discord.Member `json:"members"`

	ChunkIndex int `json:"chunk_index"`
	ChunkCount int `json:"chunk_count"`

	// Whatever's not found goes here
	NotFound []string `json:"not_found,omitempty"`

	// Only filled if requested
	Presences []discord.Presence `json:"presences,omitempty"`
	Nonce     string             `json:"nonce,omitempty"`

GuildMembersChunkEvent is sent when Guild Request Members is called.

type GuildRoleCreateEvent

type GuildRoleCreateEvent struct {
	GuildID discord.GuildID `json:"guild_id"`
	Role    discord.Role    `json:"role"`

type GuildRoleDeleteEvent

type GuildRoleDeleteEvent struct {
	GuildID discord.GuildID `json:"guild_id"`
	RoleID  discord.RoleID  `json:"role_id"`

type GuildRoleUpdateEvent

type GuildRoleUpdateEvent struct {
	GuildID discord.GuildID `json:"guild_id"`
	Role    discord.Role    `json:"role"`

type GuildSubscribeData

type GuildSubscribeData struct {
	Typing     bool            `json:"typing"`
	Activities bool            `json:"activities"`
	GuildID    discord.GuildID `json:"guild_id"`

	// Channels is not documented. It's used to fetch the right members sidebar.
	Channels map[discord.ChannelID][][2]int `json:"channels,omitempty"`


type HeartbeatData

type HeartbeatData int

HeartbeatData is the last sequence number to be sent.

type HelloEvent

type HelloEvent struct {
	HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`

type Identifier

type Identifier struct {

	IdentifyShortLimit  *rate.Limiter `json:"-"`
	IdentifyGlobalLimit *rate.Limiter `json:"-"`

func DefaultIdentifier

func DefaultIdentifier(token string) *Identifier

func NewIdentifier

func NewIdentifier(data IdentifyData) *Identifier

func (*Identifier) Wait

func (i *Identifier) Wait(ctx context.Context) error

type IdentifyData

type IdentifyData struct {
	Token      string             `json:"token"`
	Properties IdentifyProperties `json:"properties"`

	Compress           bool `json:"compress,omitempty"`        // true
	LargeThreshold     uint `json:"large_threshold,omitempty"` // 50
	GuildSubscriptions bool `json:"guild_subscriptions"`       // true

	Shard *Shard `json:"shard,omitempty"` // [ shard_id, num_shards ]

	Presence *UpdateStatusData `json:"presence,omitempty"`

	Intents Intents `json:"intents,omitempty"`

func (*IdentifyData) SetShard

func (i *IdentifyData) SetShard(id, num int)

type IdentifyProperties

type IdentifyProperties struct {
	// Required
	OS      string `json:"os"`      // GOOS
	Browser string `json:"browser"` // Arikawa
	Device  string `json:"device"`  // Arikawa

	// Optional
	BrowserUserAgent string `json:"browser_user_agent,omitempty"`
	BrowserVersion   string `json:"browser_version,omitempty"`
	OsVersion        string `json:"os_version,omitempty"`
	Referrer         string `json:"referrer,omitempty"`
	ReferringDomain  string `json:"referring_domain,omitempty"`

type Intents added in v0.1.5

type Intents uint32

Intents for the new Discord API feature, documented at

const (
	IntentGuilds Intents = 1 << iota

type InvalidSessionEvent

type InvalidSessionEvent bool

InvalidSessionEvent indicates if the event is resumable.

type InviteCreateEvent added in v0.7.3

type InviteCreateEvent struct {
	Code      string            `json:"code"`
	CreatedAt discord.Timestamp `json:"created_at"`
	ChannelID discord.ChannelID `json:"channel_id"`
	GuildID   discord.GuildID   `json:"guild_id,omitempty"`

	// Similar to discord.Invite
	Inviter    *discord.User          `json:"inviter,omitempty"`
	Target     *discord.User          `json:"target_user,omitempty"`
	TargetType discord.InviteUserType `json:"target_user_type,omitempty"`


type InviteDeleteEvent added in v0.7.3

type InviteDeleteEvent struct {
	Code      string            `json:"code"`
	ChannelID discord.ChannelID `json:"channel_id"`
	GuildID   discord.GuildID   `json:"guild_id,omitempty"`

type MessageAckEvent added in v0.1.4

type MessageAckEvent struct {
	MessageID discord.MessageID `json:"message_id"`
	ChannelID discord.ChannelID `json:"channel_id"`

type MessageCreateEvent

type MessageCreateEvent struct {
	Member *discord.Member `json:"member,omitempty"`

type MessageDeleteBulkEvent

type MessageDeleteBulkEvent struct {
	IDs       []discord.MessageID `json:"ids"`
	ChannelID discord.ChannelID   `json:"channel_id"`
	GuildID   discord.GuildID     `json:"guild_id,omitempty"`

type MessageDeleteEvent

type MessageDeleteEvent struct {
	ID        discord.MessageID `json:"id"`
	ChannelID discord.ChannelID `json:"channel_id"`
	GuildID   discord.GuildID   `json:"guild_id,omitempty"`

type MessageReactionAddEvent

type MessageReactionAddEvent struct {
	UserID    discord.UserID    `json:"user_id"`
	ChannelID discord.ChannelID `json:"channel_id"`
	MessageID discord.MessageID `json:"message_id"`

	Emoji discord.Emoji `json:"emoji,omitempty"`

	GuildID discord.GuildID `json:"guild_id,omitempty"`
	Member  *discord.Member `json:"member,omitempty"`

type MessageReactionRemoveAllEvent

type MessageReactionRemoveAllEvent struct {
	ChannelID discord.ChannelID `json:"channel_id"`
	MessageID discord.MessageID `json:"message_id"`
	GuildID   discord.GuildID   `json:"guild_id,omitempty"`

type MessageReactionRemoveEmoji added in v0.3.1

type MessageReactionRemoveEmoji struct {
	ChannelID discord.ChannelID `json:"channel_id"`
	MessageID discord.MessageID `json:"message_id"`
	Emoji     discord.Emoji     `json:"emoji"`
	GuildID   discord.GuildID   `json:"guild_id,omitempty"`

type MessageReactionRemoveEvent

type MessageReactionRemoveEvent struct {
	UserID    discord.UserID    `json:"user_id"`
	ChannelID discord.ChannelID `json:"channel_id"`
	MessageID discord.MessageID `json:"message_id"`
	Emoji     discord.Emoji     `json:"emoji"`
	GuildID   discord.GuildID   `json:"guild_id,omitempty"`

type MessageUpdateEvent

type MessageUpdateEvent struct {
	Member *discord.Member `json:"member,omitempty"`

type OPCode

type OPCode = wsutil.OPCode
const (
	DispatchOP            OPCode = 0 // recv
	HeartbeatOP           OPCode = 1 // send/recv
	IdentifyOP            OPCode = 2 // send...
	StatusUpdateOP        OPCode = 3 //
	VoiceStateUpdateOP    OPCode = 4 //
	VoiceServerPingOP     OPCode = 5 //
	ResumeOP              OPCode = 6 //
	ReconnectOP           OPCode = 7 // recv
	RequestGuildMembersOP OPCode = 8 // send
	InvalidSessionOP      OPCode = 9 // recv...
	HelloOP               OPCode = 10
	HeartbeatAckOP        OPCode = 11
	CallConnectOP         OPCode = 13
	GuildSubscriptionsOP  OPCode = 14

type PresenceUpdateEvent

type PresenceUpdateEvent struct {

Clients may only update their game status 5 times per 20 seconds.

type ReadState added in v0.1.5

type ReadState struct {
	ChannelID     discord.ChannelID `json:"id"`
	LastMessageID discord.MessageID `json:"last_message_id"`
	MentionCount  int               `json:"mention_count"`

type ReadyEvent

type ReadyEvent struct {
	Version int `json:"version"`

	User      discord.User `json:"user"`
	SessionID string       `json:"session_id"`

	PrivateChannels []discord.Channel  `json:"private_channels"`
	Guilds          []GuildCreateEvent `json:"guilds"`

	Shard *Shard `json:"shard"`

	// Undocumented fields
	Settings          *UserSettings       `json:"user_settings,omitempty"`
	UserGuildSettings []UserGuildSettings `json:"user_guild_settings,omitempty"`

	ReadState []ReadState        `json:"read_state,omitempty"`
	Presences []discord.Presence `json:"presences,omitempty"`

	Relationships []discord.Relationship    `json:"relationships,omitempty"`
	Notes         map[discord.UserID]string `json:"notes,omitempty"`

type RelationshipAddEvent added in v0.10.0

type RelationshipAddEvent struct {

type RelationshipRemoveEvent added in v0.10.0

type RelationshipRemoveEvent struct {

type RequestGuildMembersData

type RequestGuildMembersData struct {
	GuildID []discord.GuildID `json:"guild_id"`
	UserIDs []discord.UserID  `json:"user_ids,omitempty"`

	Query     string `json:"query"`
	Limit     uint   `json:"limit"`
	Presences bool   `json:"presences,omitempty"`
	Nonce     string `json:"nonce,omitempty"`

type ResumeData

type ResumeData struct {
	Token     string `json:"token"`
	SessionID string `json:"session_id"`
	Sequence  int64  `json:"seq"`

type Sequence

type Sequence int64

func NewSequence

func NewSequence() *Sequence

func (*Sequence) Get

func (s *Sequence) Get() int64

func (*Sequence) Set

func (s *Sequence) Set(seq int64)

type SessionStartLimit added in v0.3.2

type SessionStartLimit struct {
	Total      int                  `json:"total"`
	Remaining  int                  `json:"remaining"`
	ResetAfter discord.Milliseconds `json:"reset_after"`

SessionStartLimit is the information on the current session start limit. It's used in BotData.

type SessionsReplaceEvent added in v0.1.5

type SessionsReplaceEvent []struct {
	Status    discord.Status `json:"status"`
	SessionID string         `json:"session_id"`

	Game       *discord.Activity  `json:"game"`
	Activities []discord.Activity `json:"activities"`

	ClientInfo struct {
		Version int    `json:"version"`
		OS      string `json:"os"`
		Client  string `json:"client"`
	} `json:"client_info"`

	Active bool `json:"active"`

SessionsReplaceEvent is an undocumented user event. It's likely used for current user's presence updates.

type SettingsChannelOverride added in v0.0.2

type SettingsChannelOverride struct {
	Muted bool `json:"muted"`

	MessageNotifications UserNotification  `json:"message_notifications"`
	ChannelID            discord.ChannelID `json:"channel_id"`

A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.

type Shard

type Shard [2]int

func DefaultShard

func DefaultShard() *Shard

func (Shard) NumShards

func (s Shard) NumShards() int

func (Shard) ShardID

func (s Shard) ShardID() int

type TypingStartEvent

type TypingStartEvent struct {
	ChannelID discord.ChannelID     `json:"channel_id"`
	UserID    discord.UserID        `json:"user_id"`
	Timestamp discord.UnixTimestamp `json:"timestamp"`

	GuildID discord.GuildID `json:"guild_id,omitempty"`
	Member  *discord.Member `json:"member,omitempty"`

type UpdateStatusData

type UpdateStatusData struct {
	Since discord.UnixMsTimestamp `json:"since"` // 0 if not idle

	// Both fields are nullable.
	Game       *discord.Activity   `json:"game,omitempty"`
	Activities *[]discord.Activity `json:"activities,omitempty"`

	Status discord.Status `json:"status"`
	AFK    bool           `json:"afk"`
var Presence *UpdateStatusData

Presence is used as the default presence when initializing a new Gateway.

type UpdateVoiceStateData

type UpdateVoiceStateData struct {
	GuildID   discord.GuildID   `json:"guild_id"`
	ChannelID discord.ChannelID `json:"channel_id"` // nullable
	SelfMute  bool              `json:"self_mute"`
	SelfDeaf  bool              `json:"self_deaf"`

type UserGuildSettings added in v0.0.2

type UserGuildSettings struct {
	GuildID discord.GuildID `json:"guild_id"`

	SuppressEveryone bool `json:"suppress_everyone"`
	SuppressRoles    bool `json:"suppress_roles"`
	Muted            bool `json:"muted"`
	MobilePush       bool `json:"mobile_push"`

	MessageNotifications UserNotification          `json:"message_notifications"`
	ChannelOverrides     []SettingsChannelOverride `json:"channel_overrides"`

A UserGuildSettings stores data for a users guild settings.

type UserGuildSettingsUpdateEvent added in v0.0.2

type UserGuildSettingsUpdateEvent struct {


type UserNoteUpdateEvent added in v0.1.4

type UserNoteUpdateEvent struct {
	ID   discord.UserID `json:"id"`
	Note string         `json:"note"`


type UserNotification added in v0.2.0

type UserNotification uint8

UserNotification is the notification setting for a channel or guild.

const (
	AllNotifications UserNotification = iota

type UserSettings added in v0.0.2

type UserSettings struct {
	ShowCurrentGame         bool  `json:"show_current_game"`
	DefaultGuildsRestricted bool  `json:"default_guilds_restricted"`
	InlineAttachmentMedia   bool  `json:"inline_attachment_media"`
	InlineEmbedMedia        bool  `json:"inline_embed_media"`
	GIFAutoPlay             bool  `json:"gif_auto_play"`
	RenderEmbeds            bool  `json:"render_embeds"`
	RenderReactions         bool  `json:"render_reactions"`
	AnimateEmoji            bool  `json:"animate_emoji"`
	EnableTTSCommand        bool  `json:"enable_tts_command"`
	MessageDisplayCompact   bool  `json:"message_display_compact"`
	ConvertEmoticons        bool  `json:"convert_emoticons"`
	ExplicitContentFilter   uint8 `json:"explicit_content_filter"` // ???
	DisableGamesTab         bool  `json:"disable_games_tab"`
	DeveloperMode           bool  `json:"developer_mode"`
	DetectPlatformAccounts  bool  `json:"detect_platform_accounts"`
	StreamNotification      bool  `json:"stream_notification_enabled"`
	AccessibilityDetection  bool  `json:"allow_accessibility_detection"`
	ContactSync             bool  `json:"contact_sync_enabled"`
	NativePhoneIntegration  bool  `json:"native_phone_integration_enabled"`

	Locale string `json:"locale"`
	Theme  string `json:"theme"`

	GuildPositions   []discord.GuildID `json:"guild_positions"`
	GuildFolders     []GuildFolder     `json:"guild_folders"`
	RestrictedGuilds []discord.GuildID `json:"restricted_guilds"`

	FriendSourceFlags struct {
		All           bool `json:"all"`
		MutualGuilds  bool `json:"mutual_guilds"`
		MutualFriends bool `json:"mutual_friends"`
	} `json:"friend_source_flags"`

	Status       discord.Status `json:"status"`
	CustomStatus struct {
		Text      string            `json:"text"`
		ExpiresAt discord.Timestamp `json:"expires_at,omitempty"`
		EmojiID   discord.EmojiID   `json:"emoji_id,string"`
		EmojiName string            `json:"emoji_name"`
	} `json:"custom_status"`

type UserSettingsUpdateEvent added in v0.0.2

type UserSettingsUpdateEvent struct {


type VoiceServerUpdateEvent

type VoiceServerUpdateEvent struct {
	Token    string          `json:"token"`
	GuildID  discord.GuildID `json:"guild_id"`
	Endpoint string          `json:"endpoint"`

type WebhooksUpdateEvent

type WebhooksUpdateEvent struct {
	GuildID   discord.GuildID   `json:"guild_id"`
	ChannelID discord.ChannelID `json:"channel_id"`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL