Documentation ¶
Overview ¶
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.
Example ¶
package main import ( "context" "log" "os" "os/signal" "github.com/diamondburned/arikawa/v3/gateway" ) func main() { token := os.Getenv("BOT_TOKEN") ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() g, err := gateway.NewWithIntents(ctx, token, gateway.IntentGuilds) if err != nil { log.Fatalln("failed to initialize gateway:", err) } for op := range g.Connect(ctx) { switch data := op.Data.(type) { case *gateway.ReadyEvent: log.Println("logged in as", data.User.Username) case *gateway.MessageCreateEvent: log.Println("got message", data.Content) } } }
Output:
Index ¶
- Constants
- Variables
- func AddGatewayParams(baseURL string) string
- func BotURL(ctx context.Context, token string) (*api.BotData, error)
- func ConvertSupplementalMembers(sms []SupplementalMember) []discord.Member
- func ConvertSupplementalPresences(sps []SupplementalPresence) []discord.Presence
- func URL(ctx context.Context) (string, error)
- type ChannelCreateEvent
- type ChannelDeleteEvent
- type ChannelPinsUpdateEvent
- type ChannelUnreadUpdateEvent
- type ChannelUpdateEvent
- type ClientState
- type CustomUserStatus
- type Event
- type FriendSourceFlags
- type Gateway
- func New(ctx context.Context, token string) (*Gateway, error)
- func NewCustom(gatewayURL, token string) *Gateway
- func NewCustomWithIdentifier(gatewayURL string, id Identifier, opts *ws.GatewayOpts) *Gateway
- func NewFromState(gatewayURL string, state State, opts *ws.GatewayOpts) *Gateway
- func NewWithIdentifier(ctx context.Context, id Identifier) (*Gateway, error)
- func NewWithIntents(ctx context.Context, token string, intents ...Intents) (*Gateway, error)
- func (g *Gateway) AddIntents(i Intents)
- func (g *Gateway) Connect(ctx context.Context) <-chan ws.Op
- func (g *Gateway) EchoBeat() time.Time
- func (g *Gateway) LastError() error
- func (g *Gateway) Latency() time.Duration
- func (g *Gateway) Opts() *ws.GatewayOpts
- func (g *Gateway) Send(ctx context.Context, data ws.Event) error
- func (g *Gateway) SentBeat() time.Time
- func (g *Gateway) SetState(state State)
- func (g *Gateway) State() State
- type GuildAuditLogEntryCreateEvent
- type GuildBanAddEvent
- type GuildBanRemoveEvent
- type GuildCreateEvent
- type GuildDeleteEvent
- type GuildEmojisUpdateEvent
- type GuildFolder
- type GuildFolderID
- type GuildIntegrationsUpdateEvent
- type GuildMemberAddEvent
- type GuildMemberListGroup
- type GuildMemberListOp
- type GuildMemberListOpItem
- type GuildMemberListUpdate
- type GuildMemberRemoveEvent
- type GuildMemberUpdateEvent
- type GuildMembersChunkEvent
- type GuildRoleCreateEvent
- type GuildRoleDeleteEvent
- type GuildRoleUpdateEvent
- type GuildScheduledEventCreateEvent
- type GuildScheduledEventDeleteEvent
- type GuildScheduledEventUpdateEvent
- type GuildScheduledEventUserAddEvent
- type GuildScheduledEventUserRemoveEvent
- type GuildSubscribeCommand
- type GuildUpdateEvent
- type HeartbeatAckEvent
- type HeartbeatCommand
- type HelloEvent
- type Identifier
- type IdentifyCommand
- type IdentifyProperties
- type Intents
- type InteractionCreateEvent
- type InvalidSessionEvent
- type InviteCreateEvent
- type InviteDeleteEvent
- type MergedPresences
- type MessageAckEvent
- type MessageCreateEvent
- type MessageDeleteBulkEvent
- type MessageDeleteEvent
- type MessageReactionAddEvent
- type MessageReactionRemoveAllEvent
- type MessageReactionRemoveEmojiEvent
- type MessageReactionRemoveEvent
- type MessageUpdateEvent
- type PresenceUpdateEvent
- type PresencesReplaceEvent
- type ReadState
- type ReadyEvent
- type ReadyEventExtras
- type ReadySupplementalEvent
- type ReconnectEvent
- type RelationshipAddEvent
- type RelationshipRemoveEvent
- type RequestGuildMembersCommand
- type ResumeCommand
- type ResumedEvent
- type SessionsReplaceEvent
- type Shard
- type State
- type SupplementalMember
- type SupplementalPresence
- type ThreadCreateEvent
- type ThreadDeleteEvent
- type ThreadListSyncEvent
- type ThreadMemberUpdateEvent
- type ThreadMembersUpdateEvent
- type ThreadUpdateEvent
- type TypingStartEvent
- type UpdatePresenceCommand
- type UpdateVoiceStateCommand
- type UserChannelOverride
- type UserGuildSetting
- type UserGuildSettingsUpdateEvent
- type UserMuteConfig
- type UserNoteUpdateEvent
- type UserNotification
- type UserSession
- type UserSettings
- type UserSettingsUpdateEvent
- type UserUpdateEvent
- type VoiceServerUpdateEvent
- type VoiceStateUpdateEvent
- type WebhooksUpdateEvent
Examples ¶
Constants ¶
const CodeInvalidSequence = 4007
CodeInvalidSequence is the code returned by Discord to signal that the given sequence number is invalid.
const CodeShardingRequired = 4011
CodeShardingRequired is the code returned by Discord to signal that the bot must reshard before proceeding. For more information, see https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-gateway-close-event-codes.
const IntentGuildBans = IntentGuildModeration
IntentGuildBans is an alias to IntentGuildModeration.
Deprecated: IntentGuildModeration is the more correct constant to use.
Variables ¶
var ( Version = api.Version Encoding = "json" )
var DefaultGatewayOpts = ws.GatewayOpts{ ReconnectDelay: func(try int) time.Duration { return time.Duration(4+(2*try)) * time.Second }, FatalCloseCodes: []int{ 4004, 4010, 4011, 4012, 4013, 4014, }, DialTimeout: 0, ReconnectAttempt: 0, AlwaysCloseGracefully: true, }
DefaultGatewayOpts contains the default options to be used for connecting to the gateway.
var DefaultIdentity = IdentifyProperties{ OS: runtime.GOOS, Browser: "Arikawa", Device: "Arikawa", }
DefaultIdentity is used as the default identity when initializing a new Gateway.
var DefaultShard = &Shard{0, 1}
DefaultShard returns the default shard configuration of 1 shard total, in which the current shard ID is 0.
var EventIntents = map[ws.EventType]Intents{ "GUILD_CREATE": IntentGuilds, "GUILD_UPDATE": IntentGuilds, "GUILD_DELETE": IntentGuilds, "GUILD_ROLE_CREATE": IntentGuilds, "GUILD_ROLE_UPDATE": IntentGuilds, "GUILD_ROLE_DELETE": IntentGuilds, "CHANNEL_CREATE": IntentGuilds, "CHANNEL_UPDATE": IntentGuilds, "CHANNEL_DELETE": IntentGuilds, "CHANNEL_PINS_UPDATE": IntentGuilds | IntentDirectMessages, "GUILD_MEMBER_ADD": IntentGuildMembers, "GUILD_MEMBER_REMOVE": IntentGuildMembers, "GUILD_MEMBER_UPDATE": IntentGuildMembers, "GUILD_AUDIT_LOG_ENTRY_CREATE": IntentGuildModeration, "GUILD_BAN_ADD": IntentGuildModeration, "GUILD_BAN_REMOVE": IntentGuildModeration, "GUILD_EMOJIS_UPDATE": IntentGuildEmojis, "GUILD_INTEGRATIONS_UPDATE": IntentGuildIntegrations, "WEBHOOKS_UPDATE": IntentGuildWebhooks, "INVITE_CREATE": IntentGuildInvites, "INVITE_DELETE": IntentGuildInvites, "VOICE_STATE_UPDATE": IntentGuildVoiceStates, "PRESENCE_UPDATE": IntentGuildPresences, "MESSAGE_CREATE": IntentGuildMessages | IntentDirectMessages, "MESSAGE_UPDATE": IntentGuildMessages | IntentDirectMessages, "MESSAGE_DELETE": IntentGuildMessages | IntentDirectMessages, "MESSAGE_DELETE_BULK": IntentGuildMessages, "MESSAGE_REACTION_ADD": IntentGuildMessageReactions | IntentDirectMessageReactions, "MESSAGE_REACTION_REMOVE": IntentGuildMessageReactions | IntentDirectMessageReactions, "MESSAGE_REACTION_REMOVE_ALL": IntentGuildMessageReactions | IntentDirectMessageReactions, "MESSAGE_REACTION_REMOVE_EMOJI": IntentGuildMessageReactions | IntentDirectMessageReactions, "TYPING_START": IntentGuildMessageTyping | IntentDirectMessageTyping, "GUILD_SCHEDULED_EVENT_CREATE": IntentGuildScheduledEvents, "GUILD_SCHEDULED_EVENT_UPDATE": IntentGuildScheduledEvents, "GUILD_SCHEDULED_EVENT_DELETE": IntentGuildScheduledEvents, "GUILD_SCHEDULED_EVENT_USER_ADD": IntentGuildScheduledEvents, "GUILD_SCHEDULED_EVENT_USER_REMOVE": IntentGuildScheduledEvents, }
EventIntents maps event types to intents.
var OpUnmarshalers = ws.NewOpUnmarshalers()
OpUnmarshalers contains the Op unmarshalers for this gateway.
var PrivilegedIntents = []Intents{ IntentGuildPresences, IntentGuildMembers, }
PrivilegedIntents contains a list of privileged intents that Discord requires bots to have these intents explicitly enabled in the Developer Portal.
var ReadyEventKeepRaw = false
ReadyEventKeepRaw, if true, will make the gateway keep a copy of the raw JSON body that makes up the Ready event. This is useful for non-bots.
Functions ¶
func AddGatewayParams ¶
AddGatewayParams appends into the given URL string the gateway URL parameters.
func BotURL ¶
BotURL fetches the Gateway URL along with extra metadata. The token passed in will NOT be prefixed with Bot.
func ConvertSupplementalMembers ¶
func ConvertSupplementalMembers(sms []SupplementalMember) []discord.Member
ConvertSupplementalMembers converts a SupplementalMember to a regular Member.
func ConvertSupplementalPresences ¶
func ConvertSupplementalPresences(sps []SupplementalPresence) []discord.Presence
ConvertSupplementalPresences converts a SupplementalPresence to a regular Presence with an empty GuildID.
Types ¶
type ChannelCreateEvent ¶
ChannelCreateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#channels
func (*ChannelCreateEvent) EventType ¶
func (*ChannelCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*ChannelCreateEvent) Op ¶
func (*ChannelCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ChannelDeleteEvent ¶
ChannelDeleteEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#channels
func (*ChannelDeleteEvent) EventType ¶
func (*ChannelDeleteEvent) EventType() ws.EventType
EventType implements Event.
func (*ChannelDeleteEvent) Op ¶
func (*ChannelDeleteEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
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"` }
ChannelPinsUpdateEvent is a dispatch event.
func (*ChannelPinsUpdateEvent) EventType ¶
func (*ChannelPinsUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*ChannelPinsUpdateEvent) Op ¶
func (*ChannelPinsUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ChannelUnreadUpdateEvent ¶
type ChannelUnreadUpdateEvent struct { GuildID discord.GuildID `json:"guild_id"` ChannelUnreadUpdates []struct { ID discord.ChannelID `json:"id"` LastMessageID discord.MessageID `json:"last_message_id"` } }
ChannelUnreadUpdateEvent is a dispatch event.
func (*ChannelUnreadUpdateEvent) EventType ¶
func (*ChannelUnreadUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*ChannelUnreadUpdateEvent) Op ¶
func (*ChannelUnreadUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ChannelUpdateEvent ¶
ChannelUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#channels
func (*ChannelUpdateEvent) EventType ¶
func (*ChannelUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*ChannelUpdateEvent) Op ¶
func (*ChannelUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ClientState ¶
type ClientState struct { GuildHashes map[discord.GuildID]interface{} `json:"guild_hashes"` // {} HighestLastMessageID discord.MessageID `json:"highest_last_message_id"` // "0" ReadStateVersion int `json:"read_state_version"` // 0 UserGuildSettingsVersion int `json:"user_guild_settings_version"` // -1 UserSettingsVersion int `json:"user_settings_version"` // -1 }
ClientState describes the undocumented client_state field in the Identify command. Little is known about this type.
type CustomUserStatus ¶
type CustomUserStatus struct { Text string `json:"text"` ExpiresAt discord.Timestamp `json:"expires_at,omitempty"` EmojiID discord.EmojiID `json:"emoji_id,string"` EmojiName string `json:"emoji_name"` }
CustomUserStatus is the custom user status that allows setting an emoji and a piece of text on each user.
type Event ¶
Event is a type alias for ws.Event. It exists for convenience and describes the same event as any other ws.Event.
type FriendSourceFlags ¶
type FriendSourceFlags struct { All bool `json:"all,omitempty"` MutualGuilds bool `json:"mutual_guilds,omitempty"` MutualFriends bool `json:"mutual_friends,omitempty"` }
FriendSourceFlags describes sources that friend requests could be sent from. It belongs to the UserSettings struct and is undocumented.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway describes an instance that handles the Discord gateway. It is basically an abstracted concurrent event loop that the user could signal to start connecting to the Discord gateway server.
func NewCustom ¶
NewCustom creates a new Gateway with a custom gateway URL and a new Identifier. Most bots connecting to the official server should not use these custom functions.
func NewCustomWithIdentifier ¶
func NewCustomWithIdentifier(gatewayURL string, id Identifier, opts *ws.GatewayOpts) *Gateway
NewCustomWithIdentifier creates a new Gateway with a custom gateway URL and a pre-existing Identifier. If opts is nil, then DefaultGatewayOpts is used.
func NewFromState ¶
func NewFromState(gatewayURL string, state State, opts *ws.GatewayOpts) *Gateway
NewFromState creates a new gateway from the given state and optionally gateway options. If opts is nil, then DefaultGatewayOpts is used.
func NewWithIdentifier ¶
func NewWithIdentifier(ctx context.Context, id Identifier) (*Gateway, error)
NewWithIdentifier creates a new Gateway with the given gateway identifier and the default everything. Sharded bots should prefer this function for the shared identifier. The given Identifier will be modified.
func NewWithIntents ¶
NewWithIntents creates a new Gateway with the given intents and the default stdlib JSON driver. Refer to NewGatewayWithDriver and AddIntents.
func (*Gateway) AddIntents ¶
AddIntents adds a Gateway Intent before connecting to the Gateway. This function will only work before Connect() is called. Calling it once Connect() is called will result in a panic.
func (*Gateway) Connect ¶
Connect starts the background goroutine that tries its best to maintain a stable connection to the Discord gateway. To the user, the gateway should appear to be working seamlessly.
Behaviors ¶
There are several behaviors that the gateway will overload onto the channel.
Once the gateway has exited, fatally or not, the event channel returned by Connect will be closed. The user should therefore know whether or not the gateway has exited by spinning on the channel until it is closed.
If Connect is called twice, the second call will return the same exact channel that the first call has made without starting any new goroutines, except if the gateway is already closed, then a new gateway will spin up with the existing gateway state.
If the gateway stumbles upon any background errors, it will do its best to recover from it, but errors will be notified to the user using the BackgroundErrorEvent event. The user can type-assert the Op's data field, like so:
switch data := ev.Data.(type) { case *gateway.BackgroundErrorEvent: log.Println("gateway error:", data.Error) }
Closing ¶
As outlined in the first paragraph, closing the gateway would involve cancelling the context that's given to gateway. If AlwaysCloseGracefully is true (which it is by default), then the gateway is closed gracefully, and the session ID is invalidated.
To wait until the gateway has completely successfully exited, the user can keep spinning on the event loop:
for op := range ch { select op.Data.(type) { case *gateway.ReadyEvent: // Close the gateway on READY. cancel() } } // Gateway is now completely closed.
To capture the final close errors, the user can use the Error method once the event channel is closed, like so:
var err error for op := range ch { switch data := op.Data.(type) { case *gateway.ReadyEvent: cancel() } } // Gateway is now completely closed. if gateway.LastError() != nil { return gateway.LastError() }
func (*Gateway) EchoBeat ¶
EchoBeat returns the last time that the heartbeat was acknowledged. It is similar to SentBeat.
func (*Gateway) LastError ¶
LastError returns the last error that the gateway has received. It only returns a valid error if the gateway's event loop as exited. If the event loop hasn't been started AND stopped, the function will panic.
func (*Gateway) Latency ¶
Latency is a convenient function around SentBeat and EchoBeat. It subtracts the EchoBeat with the SentBeat.
func (*Gateway) Opts ¶ added in v3.2.0
func (g *Gateway) Opts() *ws.GatewayOpts
Opts returns a copy of the gateway options that are being used.
func (*Gateway) SentBeat ¶
SentBeat returns the last time that the heart was beaten. If the gateway has never connected, then a zero-value time is returned.
type GuildAuditLogEntryCreateEvent ¶ added in v3.3.0
type GuildAuditLogEntryCreateEvent struct {
discord.AuditLogEntry
}
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildAuditLogEntryCreateEvent) EventType ¶ added in v3.3.0
func (*GuildAuditLogEntryCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildAuditLogEntryCreateEvent) Op ¶ added in v3.3.0
func (*GuildAuditLogEntryCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildBanAddEvent ¶
type GuildBanAddEvent struct { GuildID discord.GuildID `json:"guild_id"` User discord.User `json:"user"` }
GuildBanAddEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildBanAddEvent) EventType ¶
func (*GuildBanAddEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildBanAddEvent) Op ¶
func (*GuildBanAddEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildBanRemoveEvent ¶
type GuildBanRemoveEvent struct { GuildID discord.GuildID `json:"guild_id"` User discord.User `json:"user"` }
GuildBanRemoveEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildBanRemoveEvent) EventType ¶
func (*GuildBanRemoveEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildBanRemoveEvent) Op ¶
func (*GuildBanRemoveEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildCreateEvent ¶
type GuildCreateEvent struct { discord.Guild Joined discord.Timestamp `json:"joined_at,omitempty"` Large bool `json:"large,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"` Threads []discord.Channel `json:"threads,omitempty"` Presences []discord.Presence `json:"presences,omitempty"` }
GuildCreateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildCreateEvent) EventType ¶
func (*GuildCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildCreateEvent) Op ¶
func (*GuildCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildDeleteEvent ¶
type GuildDeleteEvent struct { ID discord.GuildID `json:"id"` Unavailable bool `json:"unavailable"` }
GuildDeleteEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildDeleteEvent) EventType ¶
func (*GuildDeleteEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildDeleteEvent) Op ¶
func (*GuildDeleteEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildEmojisUpdateEvent ¶
type GuildEmojisUpdateEvent struct { GuildID discord.GuildID `json:"guild_id"` Emojis []discord.Emoji `json:"emojis"` }
GuildEmojisUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildEmojisUpdateEvent) EventType ¶
func (*GuildEmojisUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildEmojisUpdateEvent) Op ¶
func (*GuildEmojisUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildFolder ¶
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 ¶
type GuildFolderID int64
GuildFolderID is possibly a snowflake. It can also be 0 (null) or a low number of unknown significance.
func (GuildFolderID) MarshalJSON ¶
func (g GuildFolderID) MarshalJSON() ([]byte, error)
func (*GuildFolderID) UnmarshalJSON ¶
func (g *GuildFolderID) UnmarshalJSON(b []byte) error
type GuildIntegrationsUpdateEvent ¶
GuildIntegrationsUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildIntegrationsUpdateEvent) EventType ¶
func (*GuildIntegrationsUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildIntegrationsUpdateEvent) Op ¶
func (*GuildIntegrationsUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildMemberAddEvent ¶
GuildMemberAddEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildMemberAddEvent) EventType ¶
func (*GuildMemberAddEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildMemberAddEvent) Op ¶
func (*GuildMemberAddEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildMemberListGroup ¶
type GuildMemberListGroup struct { ID string `json:"id"` // either discord.RoleID, "online" or "offline" Count uint64 `json:"count"` }
GuildMemberListGroup is a dispatch event.
type GuildMemberListOp ¶
type GuildMemberListOp struct { // Mysterious string, so far spotted to be [SYNC, INSERT, UPDATE, DELETE]. Op string `json:"op"` // NON-SYNC ONLY // Only available for Ops that aren't "SYNC". Index int `json:"index,omitempty"` Item GuildMemberListOpItem `json:"item,omitempty"` // SYNC ONLY // Range requested in GuildSubscribeCommand. 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"` }
GuildMemberListOp is an entry of every operation in GuildMemberListUpdate.
type GuildMemberListOpItem ¶
type GuildMemberListOpItem struct { Group *GuildMemberListGroup `json:"group,omitempty"` Member *struct { discord.Member HoistedRole string `json:"hoisted_role"` Presence discord.Presence `json:"presence"` } `json:"member,omitempty"` }
GuildMemberListOpItem is a union of either Group or Member. Refer to (*GuildMemberListUpdate).Ops for more.
type GuildMemberListUpdate ¶
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 a dispatch event. It 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"` }
GuildMemberRemoveEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildMemberRemoveEvent) EventType ¶
func (*GuildMemberRemoveEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildMemberRemoveEvent) Op ¶
func (*GuildMemberRemoveEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
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"` Avatar discord.Hash `json:"avatar"` IsPending bool `json:"pending,omitempty"` CommunicationDisabledUntil discord.Timestamp `json:"communication_disabled_until"` }
GuildMemberUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildMemberUpdateEvent) EventType ¶
func (*GuildMemberUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildMemberUpdateEvent) Op ¶
func (*GuildMemberUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
func (*GuildMemberUpdateEvent) UpdateMember ¶
func (u *GuildMemberUpdateEvent) UpdateMember(m *discord.Member)
UpdateMember updates the given 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 a dispatch event. It is sent when the Guild Request Members command is sent.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildMembersChunkEvent) EventType ¶
func (*GuildMembersChunkEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildMembersChunkEvent) Op ¶
func (*GuildMembersChunkEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildRoleCreateEvent ¶
type GuildRoleCreateEvent struct { GuildID discord.GuildID `json:"guild_id"` Role discord.Role `json:"role"` }
GuildRoleCreateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildRoleCreateEvent) EventType ¶
func (*GuildRoleCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildRoleCreateEvent) Op ¶
func (*GuildRoleCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildRoleDeleteEvent ¶
type GuildRoleDeleteEvent struct { GuildID discord.GuildID `json:"guild_id"` RoleID discord.RoleID `json:"role_id"` }
GuildRoleDeleteEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildRoleDeleteEvent) EventType ¶
func (*GuildRoleDeleteEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildRoleDeleteEvent) Op ¶
func (*GuildRoleDeleteEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildRoleUpdateEvent ¶
type GuildRoleUpdateEvent struct { GuildID discord.GuildID `json:"guild_id"` Role discord.Role `json:"role"` }
GuildRoleUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildRoleUpdateEvent) EventType ¶
func (*GuildRoleUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildRoleUpdateEvent) Op ¶
func (*GuildRoleUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildScheduledEventCreateEvent ¶
type GuildScheduledEventCreateEvent struct {
discord.GuildScheduledEvent
}
GuildScheduledEventCreateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guild-scheduled-event-create
func (*GuildScheduledEventCreateEvent) EventType ¶
func (*GuildScheduledEventCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildScheduledEventCreateEvent) Op ¶
func (*GuildScheduledEventCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildScheduledEventDeleteEvent ¶
type GuildScheduledEventDeleteEvent struct {
discord.GuildScheduledEvent
}
GuildScheduledEventDeleteEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guild-scheduled-event-delete
func (*GuildScheduledEventDeleteEvent) EventType ¶
func (*GuildScheduledEventDeleteEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildScheduledEventDeleteEvent) Op ¶
func (*GuildScheduledEventDeleteEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildScheduledEventUpdateEvent ¶
type GuildScheduledEventUpdateEvent struct {
discord.GuildScheduledEvent
}
GuildScheduledEventUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guild-scheduled-event-update
func (*GuildScheduledEventUpdateEvent) EventType ¶
func (*GuildScheduledEventUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildScheduledEventUpdateEvent) Op ¶
func (*GuildScheduledEventUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildScheduledEventUserAddEvent ¶
type GuildScheduledEventUserAddEvent struct { // EventID is the id of the scheduled event EventID discord.EventID `json:"guild_scheduled_event_id"` // UserID is the id of the user being added UserID discord.UserID `json:"user_id"` // GuildID is the id of where the scheduled event belongs GuildID discord.GuildID `json:"guild_id"` }
GuildScheduledEventUserAddEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guild-scheduled-event-user-add
func (*GuildScheduledEventUserAddEvent) EventType ¶
func (*GuildScheduledEventUserAddEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildScheduledEventUserAddEvent) Op ¶
func (*GuildScheduledEventUserAddEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildScheduledEventUserRemoveEvent ¶
type GuildScheduledEventUserRemoveEvent struct { // EventID is the id of the scheduled event EventID discord.EventID `json:"guild_scheduled_event_id"` // UserID is the id of the user being removed UserID discord.UserID `json:"user_id"` // GuildID is the id of where the scheduled event belongs GuildID discord.GuildID `json:"guild_id"` }
GuildScheduledEventUserRemoveEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guild-scheduled-event-user-remove
func (*GuildScheduledEventUserRemoveEvent) EventType ¶
func (*GuildScheduledEventUserRemoveEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildScheduledEventUserRemoveEvent) Op ¶
func (*GuildScheduledEventUserRemoveEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type GuildSubscribeCommand ¶
type GuildSubscribeCommand struct { Typing bool `json:"typing"` Threads bool `json:"threads"` 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"` }
GuildSubscribeCommand is a command for Op 14. It is undocumented.
func (*GuildSubscribeCommand) EventType ¶
func (*GuildSubscribeCommand) EventType() ws.EventType
EventType implements Event.
func (*GuildSubscribeCommand) Op ¶
func (*GuildSubscribeCommand) Op() ws.OpCode
Op implements Event. It always returns Op 14.
type GuildUpdateEvent ¶
GuildUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#guilds
func (*GuildUpdateEvent) EventType ¶
func (*GuildUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*GuildUpdateEvent) Op ¶
func (*GuildUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type HeartbeatAckEvent ¶
type HeartbeatAckEvent struct{}
HeartbeatAckEvent is an event for Op 11.
func (*HeartbeatAckEvent) EventType ¶
func (*HeartbeatAckEvent) EventType() ws.EventType
EventType implements Event.
func (*HeartbeatAckEvent) Op ¶
func (*HeartbeatAckEvent) Op() ws.OpCode
Op implements Event. It always returns Op 11.
type HeartbeatCommand ¶
type HeartbeatCommand int
HeartbeatCommand is a command for Op 1. It is the last sequence number to be sent.
func (*HeartbeatCommand) EventType ¶
func (*HeartbeatCommand) EventType() ws.EventType
EventType implements Event.
func (*HeartbeatCommand) Op ¶
func (*HeartbeatCommand) Op() ws.OpCode
Op implements Event. It always returns Op 1.
type HelloEvent ¶
type HelloEvent struct {
HeartbeatInterval discord.Milliseconds `json:"heartbeat_interval"`
}
HelloEvent is an event for Op 10.
https://discord.com/developers/docs/topics/gateway#connecting-and-resuming
func (*HelloEvent) EventType ¶
func (*HelloEvent) EventType() ws.EventType
EventType implements Event.
func (*HelloEvent) Op ¶
func (*HelloEvent) Op() ws.OpCode
Op implements Event. It always returns Op 10.
type Identifier ¶
type Identifier struct { IdentifyCommand IdentifyShortLimit *rate.Limiter `json:"-"` // optional IdentifyGlobalLimit *rate.Limiter `json:"-"` // optional }
Identifier is a wrapper around IdentifyCommand to add in appropriate rate limiters.
func DefaultIdentifier ¶
func DefaultIdentifier(token string) Identifier
DefaultIdentifier creates a new default Identifier
func NewIdentifier ¶
func NewIdentifier(data IdentifyCommand) Identifier
NewIdentifier creates a new identifier with the given IdentifyCommand and default rate limiters.
func (*Identifier) QueryGateway ¶
func (id *Identifier) QueryGateway(ctx context.Context) (gatewayURL string, err error)
QueryGateway queries the gateway for the URL and updates the Identifier with the appropriate information.
type IdentifyCommand ¶
type IdentifyCommand struct { Token string `json:"token"` Properties IdentifyProperties `json:"properties"` Compress bool `json:"compress,omitempty"` // true LargeThreshold uint `json:"large_threshold,omitempty"` // 50 Shard *Shard `json:"shard,omitempty"` // [ shard_id, num_shards ] Presence *UpdatePresenceCommand `json:"presence,omitempty"` // ClientState is the client state for a user's accuont. Bot accounts should // NOT touch this field. ClientState *ClientState `json:"client_state,omitempty"` // Capabilities defines the client's capabilities when connecting to the // gateway with a user account. Bot accounts should NOT touch this field. // The official client sets this at 125 at the time of this commit. Capabilities int `json:"capabilities,omitempty"` // Intents specifies which groups of events the gateway // connection will receive. // // For user accounts, it must be nil. // // For bot accounts, it must not be nil, and // Gateway.AddIntents(0) can be used if you want to // specify no intents. Intents option.Uint `json:"intents"` }
IdentifyCommand is a command for Op 2. It is the struct for a data that's sent over in an Identify command.
func DefaultIdentifyCommand ¶
func DefaultIdentifyCommand(token string) IdentifyCommand
DefaultIdentifyCommand creates a default IdentifyCommand with the given token.
func (*IdentifyCommand) AddIntents ¶
func (i *IdentifyCommand) AddIntents(intents Intents)
AddIntents adds gateway intents into the identify data.
func (*IdentifyCommand) EventType ¶
func (*IdentifyCommand) EventType() ws.EventType
EventType implements Event.
func (*IdentifyCommand) HasIntents ¶
func (i *IdentifyCommand) HasIntents(intents Intents) bool
HasIntents reports if the Gateway has the passed Intents.
If no intents are set, e.g. if using a user account, HasIntents will always return true.
func (*IdentifyCommand) Op ¶
func (*IdentifyCommand) Op() ws.OpCode
Op implements Event. It always returns Op 2.
func (*IdentifyCommand) SetShard ¶
func (i *IdentifyCommand) SetShard(id, num int)
SetShard is a helper function to set the shard configuration inside IdentifyCommand.
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 ¶
type Intents uint32
Intents for the new Discord API feature, documented at https://discord.com/developers/docs/topics/gateway#gateway-intents.
const ( IntentGuilds Intents = 1 << iota IntentGuildMembers IntentGuildModeration IntentGuildEmojis IntentGuildIntegrations IntentGuildWebhooks IntentGuildInvites IntentGuildVoiceStates IntentGuildPresences IntentGuildMessages IntentGuildMessageReactions IntentGuildMessageTyping IntentDirectMessages IntentDirectMessageReactions IntentDirectMessageTyping IntentMessageContent IntentGuildScheduledEvents )
func (Intents) IsPrivileged ¶
IsPrivileged returns true for each of the boolean that indicates the type of the privilege.
type InteractionCreateEvent ¶
type InteractionCreateEvent struct {
discord.InteractionEvent
}
InteractionCreateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#webhooks
func (*InteractionCreateEvent) EventType ¶
func (*InteractionCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*InteractionCreateEvent) Op ¶
func (*InteractionCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type InvalidSessionEvent ¶
type InvalidSessionEvent bool
InvalidSessionEvent is an event for Op 9. It indicates if the event is resumable.
https://discord.com/developers/docs/topics/gateway#connecting-and-resuming
func (*InvalidSessionEvent) EventType ¶
func (*InvalidSessionEvent) EventType() ws.EventType
EventType implements Event.
func (*InvalidSessionEvent) Op ¶
func (*InvalidSessionEvent) Op() ws.OpCode
Op implements Event. It always returns Op 9.
type InviteCreateEvent ¶
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"` discord.InviteMetadata }
InviteCreateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#invites
func (*InviteCreateEvent) EventType ¶
func (*InviteCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*InviteCreateEvent) Op ¶
func (*InviteCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type InviteDeleteEvent ¶
type InviteDeleteEvent struct { Code string `json:"code"` ChannelID discord.ChannelID `json:"channel_id"` GuildID discord.GuildID `json:"guild_id,omitempty"` }
InviteDeleteEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#invites
func (*InviteDeleteEvent) EventType ¶
func (*InviteDeleteEvent) EventType() ws.EventType
EventType implements Event.
func (*InviteDeleteEvent) Op ¶
func (*InviteDeleteEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type MergedPresences ¶
type MergedPresences struct { Guilds [][]SupplementalPresence `json:"guilds"` Friends []SupplementalPresence `json:"friends"` }
MergedPresences is the struct for presences of guilds' members and friends. It is undocumented.
type MessageAckEvent ¶
type MessageAckEvent struct { MessageID discord.MessageID `json:"message_id"` ChannelID discord.ChannelID `json:"channel_id"` }
MessageAckEvent is a dispatch event.
func (*MessageAckEvent) EventType ¶
func (*MessageAckEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageAckEvent) Op ¶
func (*MessageAckEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type MessageCreateEvent ¶
MessageCreateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageCreateEvent) EventType ¶
func (*MessageCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageCreateEvent) Op ¶
func (*MessageCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type MessageDeleteBulkEvent ¶
type MessageDeleteBulkEvent struct { IDs []discord.MessageID `json:"ids"` ChannelID discord.ChannelID `json:"channel_id"` GuildID discord.GuildID `json:"guild_id,omitempty"` }
MessageDeleteBulkEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageDeleteBulkEvent) EventType ¶
func (*MessageDeleteBulkEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageDeleteBulkEvent) Op ¶
func (*MessageDeleteBulkEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type MessageDeleteEvent ¶
type MessageDeleteEvent struct { ID discord.MessageID `json:"id"` ChannelID discord.ChannelID `json:"channel_id"` GuildID discord.GuildID `json:"guild_id,omitempty"` }
MessageDeleteEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageDeleteEvent) EventType ¶
func (*MessageDeleteEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageDeleteEvent) Op ¶
func (*MessageDeleteEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
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"` }
MessageReactionAddEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageReactionAddEvent) EventType ¶
func (*MessageReactionAddEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageReactionAddEvent) Op ¶
func (*MessageReactionAddEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type MessageReactionRemoveAllEvent ¶
type MessageReactionRemoveAllEvent struct { ChannelID discord.ChannelID `json:"channel_id"` MessageID discord.MessageID `json:"message_id"` GuildID discord.GuildID `json:"guild_id,omitempty"` }
MessageReactionRemoveAllEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageReactionRemoveAllEvent) EventType ¶
func (*MessageReactionRemoveAllEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageReactionRemoveAllEvent) Op ¶
func (*MessageReactionRemoveAllEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type MessageReactionRemoveEmojiEvent ¶
type MessageReactionRemoveEmojiEvent 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"` }
MessageReactionRemoveEmojiEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageReactionRemoveEmojiEvent) EventType ¶
func (*MessageReactionRemoveEmojiEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageReactionRemoveEmojiEvent) Op ¶
func (*MessageReactionRemoveEmojiEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
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"` }
MessageReactionRemoveEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageReactionRemoveEvent) EventType ¶
func (*MessageReactionRemoveEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageReactionRemoveEvent) Op ¶
func (*MessageReactionRemoveEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type MessageUpdateEvent ¶
MessageUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#messages
func (*MessageUpdateEvent) EventType ¶
func (*MessageUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*MessageUpdateEvent) Op ¶
func (*MessageUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type PresenceUpdateEvent ¶
PresenceUpdateEvent is a dispatch event. It represents the structure of the Presence Update Event object.
https://discord.com/developers/docs/topics/gateway#presence-update-presence-update-event-fields
func (*PresenceUpdateEvent) EventType ¶
func (*PresenceUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*PresenceUpdateEvent) Op ¶
func (*PresenceUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type PresencesReplaceEvent ¶
type PresencesReplaceEvent []PresenceUpdateEvent
PresencesReplaceEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#presence
func (*PresencesReplaceEvent) EventType ¶
func (*PresencesReplaceEvent) EventType() ws.EventType
EventType implements Event.
func (*PresencesReplaceEvent) Op ¶
func (*PresencesReplaceEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ReadState ¶
type ReadState struct { ChannelID discord.ChannelID `json:"id"` LastMessageID discord.MessageID `json:"last_message_id"` LastPinTimestamp discord.Timestamp `json:"last_pin_timestamp"` MentionCount int `json:"mention_count"` }
ReadState is a single ReadState entry. It is undocumented.
type ReadyEvent ¶
type ReadyEvent struct { Version int `json:"v"` User discord.User `json:"user"` SessionID string `json:"session_id"` PrivateChannels []discord.Channel `json:"private_channels"` Guilds []GuildCreateEvent `json:"guilds"` Shard *Shard `json:"shard,omitempty"` Application struct { ID discord.AppID `json:"id"` Flags discord.ApplicationFlags `json:"flags"` } `json:"application"` // Bot users need not concern with what's in here. This field is only // unmarshaled, not marshaled. ReadyEventExtras `json:"-"` }
ReadyEvent is a dispatch event for READY.
https://discord.com/developers/docs/topics/gateway#ready
func (*ReadyEvent) EventType ¶
func (*ReadyEvent) EventType() ws.EventType
EventType implements Event.
func (*ReadyEvent) UnmarshalJSON ¶ added in v3.2.0
func (r *ReadyEvent) UnmarshalJSON(b []byte) error
type ReadyEventExtras ¶ added in v3.2.0
type ReadyEventExtras struct { UserSettings *UserSettings `json:"user_settings,omitempty"` ReadStates []ReadState `json:"read_state,omitempty"` UserGuildSettings []UserGuildSetting `json:"user_guild_settings,omitempty"` Relationships []discord.Relationship `json:"relationships,omitempty"` Presences []discord.Presence `json:"presences,omitempty"` Sessions []UserSession `json:"sessions,omitempty"` SessionID string `json:"session_id,omitempty"` FriendSuggestionCount int `json:"friend_suggestion_count,omitempty"` GeoOrderedRTCRegions []string `json:"geo_ordered_rtc_regions,omitempty"` // RawEventBody is the raw JSON body for the Ready event. It is only // available if ReadyEventKeepRaw is true. RawEventBody json.Raw // ExtrasDecodeErrors will be non-nil if there were errors decoding the // ReadyEventExtras. ExtrasDecodeErrors []error }
ReadyEventExtras contains undocumented fields pertaining to the Ready event. This is the only event that receives this special treatment, because it's the one with the most undocumented things.
type ReadySupplementalEvent ¶
type ReadySupplementalEvent struct { Guilds []GuildCreateEvent `json:"guilds"` // only have ID and VoiceStates MergedMembers [][]SupplementalMember `json:"merged_members"` MergedPresences MergedPresences `json:"merged_presences"` }
ReadySupplementalEvent is a dispatch event for READY_SUPPLEMENTAL. It is an undocumented event. For now, this event is never used, and its usage have yet been discovered.
func (*ReadySupplementalEvent) EventType ¶
func (*ReadySupplementalEvent) EventType() ws.EventType
EventType implements Event.
func (*ReadySupplementalEvent) Op ¶
func (*ReadySupplementalEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ReconnectEvent ¶
type ReconnectEvent struct{}
ReconnectEvent is an event for Op 7.
func (*ReconnectEvent) EventType ¶
func (*ReconnectEvent) EventType() ws.EventType
EventType implements Event.
func (*ReconnectEvent) Op ¶
func (*ReconnectEvent) Op() ws.OpCode
Op implements Event. It always returns Op 7.
type RelationshipAddEvent ¶
type RelationshipAddEvent struct {
discord.Relationship
}
RelationshipAddEvent is a dispatch event. It is undocumented.
func (*RelationshipAddEvent) EventType ¶
func (*RelationshipAddEvent) EventType() ws.EventType
EventType implements Event.
func (*RelationshipAddEvent) Op ¶
func (*RelationshipAddEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type RelationshipRemoveEvent ¶
type RelationshipRemoveEvent struct {
discord.Relationship
}
RelationshipRemoveEvent is a dispatch event. It is undocumented.
func (*RelationshipRemoveEvent) EventType ¶
func (*RelationshipRemoveEvent) EventType() ws.EventType
EventType implements Event.
func (*RelationshipRemoveEvent) Op ¶
func (*RelationshipRemoveEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type RequestGuildMembersCommand ¶
type RequestGuildMembersCommand struct { // GuildIDs contains the IDs of the guilds to request data from. Multiple // guilds can only be requested when using user accounts. // // The guild_id JSON key is intentional, despite the type being an array. GuildIDs []discord.GuildID `json:"guild_id"` // UserIDs contains the IDs of the users to request data for. If this is // filled, then the Query field must be empty. UserIDs []discord.UserID `json:"user_ids,omitempty"` // Query is a string to search for matching usernames. If this is filled, // then the UserIDs field must be empty. If Query is empty, then all members // are filled for bots. Query option.String `json:"query,omitempty"` // Limit is used to specify the maximum number of members to send back when // Query is used. Limit uint `json:"limit,omitempty"` Presences bool `json:"presences"` Nonce string `json:"nonce,omitempty"` }
RequestGuildMembersCommand is a command for Op 8. Either UserIDs or (Query and Limit) must be filled.
func (*RequestGuildMembersCommand) EventType ¶
func (*RequestGuildMembersCommand) EventType() ws.EventType
EventType implements Event.
func (*RequestGuildMembersCommand) MarshalJSON ¶ added in v3.2.0
func (c *RequestGuildMembersCommand) MarshalJSON() ([]byte, error)
MarshalJSON marshals a RequestGuildMembersCommand.
func (*RequestGuildMembersCommand) Op ¶
func (*RequestGuildMembersCommand) Op() ws.OpCode
Op implements Event. It always returns Op 8.
type ResumeCommand ¶
type ResumeCommand struct { Token string `json:"token"` SessionID string `json:"session_id"` Sequence int64 `json:"seq"` }
ResumeCommand is a command for Op 6. It describes the Resume send command. This is not to be confused with ResumedEvent, which is an event that Discord sends us.
func (*ResumeCommand) EventType ¶
func (*ResumeCommand) EventType() ws.EventType
EventType implements Event.
func (*ResumeCommand) Op ¶
func (*ResumeCommand) Op() ws.OpCode
Op implements Event. It always returns Op 6.
type ResumedEvent ¶
type ResumedEvent struct{}
ResumedEvent is a dispatch event. It is sent by Discord whenever we've successfully caught up to all events after resuming.
func (*ResumedEvent) EventType ¶
func (*ResumedEvent) EventType() ws.EventType
EventType implements Event.
func (*ResumedEvent) Op ¶
func (*ResumedEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type SessionsReplaceEvent ¶
type SessionsReplaceEvent []UserSession
SessionsReplaceEvent is a dispatch event. It is undocumented. It's likely used for current user's presence updates.
func (*SessionsReplaceEvent) EventType ¶
func (*SessionsReplaceEvent) EventType() ws.EventType
EventType implements Event.
func (*SessionsReplaceEvent) Op ¶
func (*SessionsReplaceEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type Shard ¶
type Shard [2]int
Shard is a type for two numbers that represent the Bot's shard configuration. The first number is the shard's ID, which could be obtained through the ShardID method. The second number is the total number of shards, which could be obtained through the NumShards method.
type State ¶
type State struct { Identifier Identifier SessionID string Sequence int64 }
State contains the gateway state. It is a piece of data that can be shared across gateways during construction to be used for resuming a connection or starting a new one with the previous data.
The data structure itself is not thread-safe, so they may only be pulled from the gateway after it's done and set before it's done.
type SupplementalMember ¶
type SupplementalMember struct { UserID discord.UserID `json:"user_id"` Nick string `json:"nick,omitempty"` RoleIDs []discord.RoleID `json:"roles"` GuildID discord.GuildID `json:"guild_id,omitempty"` IsPending bool `json:"pending,omitempty"` HoistedRole discord.RoleID `json:"hoisted_role"` Mute bool `json:"mute"` Deaf bool `json:"deaf"` // Joined specifies when the user joined the guild. Joined discord.Timestamp `json:"joined_at"` // BoostedSince specifies when the user started boosting the guild. BoostedSince discord.Timestamp `json:"premium_since,omitempty"` }
SupplementalMember is the struct for a member in the MergedMembers field of ReadySupplementalEvent. It has slight differences to discord.Member.
type SupplementalPresence ¶
type SupplementalPresence struct { UserID discord.UserID `json:"user_id"` // Status is either "idle", "dnd", "online", or "offline". Status discord.Status `json:"status"` // Activities are the user's current activities. Activities []discord.Activity `json:"activities"` // ClientStaus is the user's platform-dependent status. ClientStatus discord.ClientStatus `json:"client_status"` // LastModified is only present in Friends. LastModified discord.UnixMsTimestamp `json:"last_modified,omitempty"` }
SupplementalPresence is a single presence for either a guild member or friend. It is used in MergedPresences and is undocumented.
type ThreadCreateEvent ¶
ThreadCreateEvent is a dispatch event. It is sent when a thread is created, relevant to the current user, or when the current user is added to a thread.
func (*ThreadCreateEvent) EventType ¶
func (*ThreadCreateEvent) EventType() ws.EventType
EventType implements Event.
func (*ThreadCreateEvent) Op ¶
func (*ThreadCreateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ThreadDeleteEvent ¶
type ThreadDeleteEvent struct { // ID is the id of this channel. ID discord.ChannelID `json:"id"` // GuildID is the id of the guild. GuildID discord.GuildID `json:"guild_id,omitempty"` // Type is the type of channel. Type discord.ChannelType `json:"type,omitempty"` // ParentID is the id of the text channel this thread was created. ParentID discord.ChannelID `json:"parent_id,omitempty"` }
ThreadDeleteEvent is a dispatch event. It is sent when a thread relevant to the current user is deleted.
func (*ThreadDeleteEvent) EventType ¶
func (*ThreadDeleteEvent) EventType() ws.EventType
EventType implements Event.
func (*ThreadDeleteEvent) Op ¶
func (*ThreadDeleteEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ThreadListSyncEvent ¶
type ThreadListSyncEvent struct { // GuildID is the id of the guild. GuildID discord.GuildID `json:"guild_id"` // ChannelIDs are the parent channel ids whose threads are being // synced. If nil, then threads were synced for the entire guild. // This slice may contain ChannelIDs that have no active threads as // well, so you know to clear that data. ChannelIDs []discord.ChannelID `json:"channel_ids,omitempty"` Threads []discord.Channel `json:"threads"` Members []discord.ThreadMember `json:"members"` }
ThreadListSyncEvent is a dispatch event. It is sent when the current user gains access to a channel.
func (*ThreadListSyncEvent) EventType ¶
func (*ThreadListSyncEvent) EventType() ws.EventType
EventType implements Event.
func (*ThreadListSyncEvent) Op ¶
func (*ThreadListSyncEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ThreadMemberUpdateEvent ¶
type ThreadMemberUpdateEvent struct {
discord.ThreadMember
}
ThreadMemberUpdateEvent is a dispatch event. It is sent when the thread member object for the current user is updated.
func (*ThreadMemberUpdateEvent) EventType ¶
func (*ThreadMemberUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*ThreadMemberUpdateEvent) Op ¶
func (*ThreadMemberUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ThreadMembersUpdateEvent ¶
type ThreadMembersUpdateEvent struct { // ID is the id of the thread. ID discord.ChannelID `json:"id"` // GuildID is the id of the guild. GuildID discord.GuildID `json:"guild_id"` // MemberCount is the approximate number of members in the thread, // capped at 50. MemberCount int `json:"member_count"` // AddedMembers are the users who were added to the thread. AddedMembers []discord.ThreadMember `json:"added_members,omitempty"` // RemovedUserIDs are the ids of the users who were removed from the // thread. RemovedMemberIDs []discord.UserID `json:"removed_member_ids,omitempty"` }
ThreadMembersUpdateEvent is a dispatch event. It is sent when anyone is added to or removed from a thread. If the current user does not have the GUILD_MEMBERS Gateway Intent, then this event will only be sent if the current user was added to or removed from the thread.
func (*ThreadMembersUpdateEvent) EventType ¶
func (*ThreadMembersUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*ThreadMembersUpdateEvent) Op ¶
func (*ThreadMembersUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type ThreadUpdateEvent ¶
ThreadUpdateEvent is a dispatch event. It is sent when a thread is updated.
func (*ThreadUpdateEvent) EventType ¶
func (*ThreadUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*ThreadUpdateEvent) Op ¶
func (*ThreadUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
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"` }
TypingStartEvent is a dispatch event.
func (*TypingStartEvent) EventType ¶
func (*TypingStartEvent) EventType() ws.EventType
EventType implements Event.
func (*TypingStartEvent) Op ¶
func (*TypingStartEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type UpdatePresenceCommand ¶
type UpdatePresenceCommand struct { Since discord.UnixMsTimestamp `json:"since"` // 0 if not idle // Activities can be null or an empty slice. Activities []discord.Activity `json:"activities"` Status discord.Status `json:"status"` AFK bool `json:"afk"` }
UpdatePresenceCommand is a command for Op 3. It is sent by this client to indicate a presence or status update.
var DefaultPresence *UpdatePresenceCommand
DefaultPresence is used as the default presence when initializing a new Gateway.
func (*UpdatePresenceCommand) EventType ¶
func (*UpdatePresenceCommand) EventType() ws.EventType
EventType implements Event.
func (*UpdatePresenceCommand) Op ¶
func (*UpdatePresenceCommand) Op() ws.OpCode
Op implements Event. It always returns Op 3.
type UpdateVoiceStateCommand ¶
type UpdateVoiceStateCommand struct { GuildID discord.GuildID `json:"guild_id"` ChannelID discord.ChannelID `json:"channel_id"` // nullable SelfMute bool `json:"self_mute"` SelfDeaf bool `json:"self_deaf"` }
UpdateVoiceStateCommand is a command for Op 4.
func (*UpdateVoiceStateCommand) EventType ¶
func (*UpdateVoiceStateCommand) EventType() ws.EventType
EventType implements Event.
func (*UpdateVoiceStateCommand) Op ¶
func (*UpdateVoiceStateCommand) Op() ws.OpCode
Op implements Event. It always returns Op 4.
type UserChannelOverride ¶
type UserChannelOverride struct { Muted bool `json:"muted"` MuteConfig *UserMuteConfig `json:"mute_config"` Notifications UserNotification `json:"message_notifications"` ChannelID discord.ChannelID `json:"channel_id"` }
A UserChannelOverride struct describes a channel settings override for a users guild settings.
type UserGuildSetting ¶
type UserGuildSetting struct { GuildID discord.GuildID `json:"guild_id"` SuppressRoles bool `json:"suppress_roles"` SuppressEveryone bool `json:"suppress_everyone"` Muted bool `json:"muted"` MuteConfig *UserMuteConfig `json:"mute_config"` MobilePush bool `json:"mobile_push"` Notifications UserNotification `json:"message_notifications"` ChannelOverrides []UserChannelOverride `json:"channel_overrides"` }
UserGuildSetting stores the settings for a single guild. It is undocumented.
type UserGuildSettingsUpdateEvent ¶
type UserGuildSettingsUpdateEvent struct {
UserGuildSetting
}
UserGuildSettingsUpdateEvent is a dispatch event. It is undocumented.
func (*UserGuildSettingsUpdateEvent) EventType ¶
func (*UserGuildSettingsUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*UserGuildSettingsUpdateEvent) Op ¶
func (*UserGuildSettingsUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type UserMuteConfig ¶
type UserMuteConfig struct { SelectedTimeWindow int `json:"selected_time_window"` EndTime discord.Timestamp `json:"end_time"` }
UserMuteConfig seems to describe the mute settings. It belongs to the UserGuildSettingEntry and UserChannelOverride structs and is undocumented.
type UserNoteUpdateEvent ¶
UserNoteUpdateEvent is a dispatch event. It is undocumented.
func (*UserNoteUpdateEvent) EventType ¶
func (*UserNoteUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*UserNoteUpdateEvent) Op ¶
func (*UserNoteUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type UserNotification ¶
type UserNotification uint8
UserNotification is the notification setting for a channel or guild.
const ( AllNotifications UserNotification = iota OnlyMentions NoNotifications GuildDefaults )
type UserSession ¶ added in v3.2.0
type UserSession struct { Status discord.Status `json:"status"` SessionID string `json:"session_id"` 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,omitempty"` }
Ready subtypes.
type UserSettings ¶
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"` AnimateStickers int `json:"animate_stickers"` 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"` TimezoneOffset int `json:"timezone_offset"` 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 FriendSourceFlags `json:"friend_source_flags"` Status discord.Status `json:"status"` CustomStatus *CustomUserStatus `json:"custom_status"` }
UserSettings is the struct for (almost) all user settings. It is undocumented.
type UserSettingsUpdateEvent ¶
type UserSettingsUpdateEvent struct {
UserSettings
}
UserSettingsUpdateEvent is a dispatch event. It is undocumented.
func (*UserSettingsUpdateEvent) EventType ¶
func (*UserSettingsUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*UserSettingsUpdateEvent) Op ¶
func (*UserSettingsUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type UserUpdateEvent ¶
UserUpdateEvent is a dispatch event.
func (*UserUpdateEvent) EventType ¶
func (*UserUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*UserUpdateEvent) Op ¶
func (*UserUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type VoiceServerUpdateEvent ¶
type VoiceServerUpdateEvent struct { Token string `json:"token"` GuildID discord.GuildID `json:"guild_id"` Endpoint string `json:"endpoint"` }
VoiceServerUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#voice
func (*VoiceServerUpdateEvent) EventType ¶
func (*VoiceServerUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*VoiceServerUpdateEvent) Op ¶
func (*VoiceServerUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type VoiceStateUpdateEvent ¶
type VoiceStateUpdateEvent struct {
discord.VoiceState
}
VoiceStateUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#voice
func (*VoiceStateUpdateEvent) EventType ¶
func (*VoiceStateUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*VoiceStateUpdateEvent) Op ¶
func (*VoiceStateUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.
type WebhooksUpdateEvent ¶
type WebhooksUpdateEvent struct { GuildID discord.GuildID `json:"guild_id"` ChannelID discord.ChannelID `json:"channel_id"` }
WebhooksUpdateEvent is a dispatch event.
https://discord.com/developers/docs/topics/gateway#webhooks
func (*WebhooksUpdateEvent) EventType ¶
func (*WebhooksUpdateEvent) EventType() ws.EventType
EventType implements Event.
func (*WebhooksUpdateEvent) Op ¶
func (*WebhooksUpdateEvent) Op() ws.OpCode
Op implements Event. It always returns 0.