Documentation
¶
Index ¶
- Constants
- Variables
- func NewState(s *Session) state.State
- type GatewayBotResponse
- type GatewayStatusUpdate
- type Identify
- type IdentifyProperties
- type RESTError
- type RESTSession
- func (s *RESTSession) Logger() *slog.Logger
- func (s *RESTSession) Request(method, urlStr string, data any, options ...discord.RequestOption) ([]byte, error)
- func (s *RESTSession) RequestRaw(method, urlStr, contentType string, b []byte, bucketID string, sequence int, ...) ([]byte, error)
- func (s *RESTSession) RequestWithBucketID(method, urlStr string, data any, bucketID string, ...) ([]byte, error)
- func (s *RESTSession) RequestWithLockedBucket(method, urlStr, contentType string, b []byte, bucket *discord.Bucket, ...) ([]byte, error)
- func (s *RESTSession) Unmarshal(bytes []byte, i any) error
- type RateLimitError
- type Session
- func (s *Session) ApplicationAPI() *applicationapi.Requester
- func (s *Session) BotAPI() *botapi.Requester
- func (s *Session) ChannelAPI() *channelapi.Requester
- func (s *Session) Close(ctx context.Context) error
- func (s *Session) CloseWithCode(ctx context.Context, closeCode websocket.StatusCode) error
- func (s *Session) EventManager() bot.EventManager
- func (s *Session) ForceClose() error
- func (s *Session) Gateway(options ...discord.RequestOption) (string, error)
- func (s *Session) GatewayBot(options ...discord.RequestOption) (*GatewayBotResponse, error)
- func (s *Session) GatewayDial(ctx context.Context, urlString string, headers http.Header) (*websocket.Conn, *http.Response, error)
- func (s *Session) GatewayWriteStruct(ctx context.Context, v any) error
- func (s *Session) GuildAPI() *guildapi.Requester
- func (s *Session) HeartbeatLatency() time.Duration
- func (s *Session) InteractionAPI() *interactionapi.Requester
- func (s *Session) InviteAPI() *inviteapi.Requester
- func (s *Session) LastHeartbeatAck() time.Time
- func (s *Session) LastHeartbeatSent() time.Time
- func (s *Session) Logger() *slog.Logger
- func (s *Session) Open(ctx context.Context) error
- func (s *Session) OpenAndBlock(ctx context.Context) error
- func (s *Session) SessionState() state.Bot
- func (s *Session) SetStateParams(params state.Params)
- func (s *Session) UserAPI() *userapi.Requester
- func (s *Session) VoiceAPI() *voice.Requester
- type SessionInformation
Constants ¶
const FailedHeartbeatAcks = 5
FailedHeartbeatAcks is the Number of heartbeat intervals to wait until forcing a connection restart.
const VERSION = "0.33.1"
VERSION of Gokord, follows Semantic Versioning. (http://semver.org/)
Variables ¶
var ( ErrShouldNotReconnect = errors.New("session should not reconnect") ErrSendingResumePacket = errors.New("cannot send resume packet") ErrHandlingMissedEvents = errors.New("cannot handle missed events") ErrInvalidSession = errors.New("invalid session") )
var ( ErrReadingReadyPacket = errors.New("cannot read READY packet") ErrIdentifying = errors.New("cannot identify") )
var ( ErrJSONUnmarshal = errors.New("json unmarshal") ErrStatusOffline = errors.New("you can't set your Status to offline") )
All error constants
var ( // ErrWSAlreadyOpen is thrown when you attempt to open a websocket that already is open. ErrWSAlreadyOpen = errors.New("web socket already opened") // ErrWSNotFound is thrown when you attempt to use a websocket that doesn't exist ErrWSNotFound = errors.New("no websocket connection exists") // ErrWSShardBounds is thrown when you try to use a shard ID that is more than the total shard count ErrWSShardBounds = errors.New("ShardID must be less than ShardCount") )
Functions ¶
Types ¶
type GatewayBotResponse ¶
type GatewayBotResponse struct {
URL string `json:"url"`
Shards int `json:"shards"`
SessionStartLimit SessionInformation `json:"session_start_limit"`
}
GatewayBotResponse stores the data for the gateway/bot response.
type GatewayStatusUpdate ¶
type GatewayStatusUpdate struct {
Since int `json:"since"`
Game status.Activity `json:"game"`
Status string `json:"status"`
AFK bool `json:"afk"`
}
GatewayStatusUpdate is sent by the client to indicate a presence or status update. https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
type Identify ¶
type Identify struct {
Token string `json:"token"`
Properties IdentifyProperties `json:"properties"`
Compress bool `json:"compress"`
LargeThreshold int `json:"large_threshold"`
Shard *[2]int `json:"shard,omitempty"`
Presence GatewayStatusUpdate `json:"presence"`
Intents discord.Intent `json:"intents"`
}
Identify is sent during initial handshake with the discord gateway. https://discord.com/developers/docs/topics/gateway#identify
type IdentifyProperties ¶
type IdentifyProperties struct {
OS string `json:"$os"`
Browser string `json:"$browser"`
Device string `json:"$device"`
Referer string `json:"$referer"`
ReferringDomain string `json:"$referring_domain"`
}
IdentifyProperties contains the "properties" portion of an Identify packet. https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
type RESTError ¶
type RESTError struct {
Request *http.Request
Response *http.Response
ResponseBody []byte
// Message may be nil.
Message *discord.APIErrorMessage
}
RESTError stores error information about a request with a bad response code. Message is not always present, there are cases where api calls can fail without returning a json message.
type RESTSession ¶ added in v0.33.0
type RESTSession struct {
// Should the session retry requests when rate limited.
Options *bot.Options
// The http.Client used for REST requests.
Client *http.Client
// The UserAgent used for REST APIs.
UserAgent string
// Used to deal with rate limits.
RateLimiter *discord.RateLimiter
// contains filtered or unexported fields
}
RESTSession is the part of the Session responsible for the REST API.
func (*RESTSession) Logger ¶ added in v0.33.0
func (s *RESTSession) Logger() *slog.Logger
func (*RESTSession) Request ¶ added in v0.33.0
func (s *RESTSession) Request(method, urlStr string, data any, options ...discord.RequestOption) ([]byte, error)
func (*RESTSession) RequestRaw ¶ added in v0.33.0
func (s *RESTSession) RequestRaw(method, urlStr, contentType string, b []byte, bucketID string, sequence int, options ...discord.RequestOption) ([]byte, error)
func (*RESTSession) RequestWithBucketID ¶ added in v0.33.0
func (s *RESTSession) RequestWithBucketID(method, urlStr string, data any, bucketID string, options ...discord.RequestOption) ([]byte, error)
func (*RESTSession) RequestWithLockedBucket ¶ added in v0.33.0
func (s *RESTSession) RequestWithLockedBucket(method, urlStr, contentType string, b []byte, bucket *discord.Bucket, sequence int, options ...discord.RequestOption) ([]byte, error)
type RateLimitError ¶
RateLimitError is returned when a request exceeds a rate limit and Session.ShouldRetryOnRateLimit is false. The request may be manually retried after waiting the duration specified by RetryAfter.
func (RateLimitError) Error ¶
func (e RateLimitError) Error() string
Error returns a rate limit error with rate limited endpoint and retry time.
type Session ¶
type Session struct {
MFA bool
// Options of the Session.
Options bot.Options
// Identify is sent during initial handshake with the discord gateway.
// https://discord.com/developers/docs/topics/gateway#identify
Identify Identify
// REST contains the Session interacting with the REST API.
REST *RESTSession
UserStorage state.Storage // UserStorage is the state.Storage used for the UserAPI
ChannelStorage state.Storage // ChannelStorage is the state.Storage used for the ChannelAPI
GuildStorage state.Storage // GuildStorage is the state.Storage used for the GuildAPI
// contains filtered or unexported fields
}
Session represents a connection to the Discord API.
func New ¶
New creates a new Discord session with provided token. If the token is for a bot, it must be prefixed with "Bot "
e.g. "Bot ..."
Or if it is an OAuth2 token, it must be prefixed with "Bearer "
e.g. "Bearer ..."
See NewWithLogLevel to modify the default slog.Level. See NewWithLoggerOptions to set the logger.Options for the logger. See NewWithLogger to set the default slog.Logger.
func NewWithLogLevel ¶ added in v0.32.0
NewWithLogLevel creates a new Discord session with provided token and set the slog.Level of the logger.
See New for the full documentation. See NewWithLoggerOptions to set the logger.Options for the logger. See NewWithLogger to set the default slog.Logger.
func NewWithLogger ¶ added in v0.32.0
NewWithLogger creates a new Discord session with provided token and set the logger.
See New for the full documentation. See NewWithLogLevel to modify the default slog.Level. See NewWithLoggerOptions to set the logger.Options for the logger.
func NewWithLoggerOptions ¶ added in v0.33.0
NewWithLoggerOptions creates a new Discord session with provided token and options for the logger.
See New for the full documentation. See NewWithLogLevel to set the slog.Level without providing other logger.Options. See NewWithLogger to set the default slog.Logger.
func (*Session) ApplicationAPI ¶ added in v0.31.0
func (s *Session) ApplicationAPI() *applicationapi.Requester
ApplicationAPI returns an applicationapi.Requester to interact with the application package.
func (*Session) BotAPI ¶ added in v0.32.0
BotAPI returns a botapi.Requester to interact with the bot package.
func (*Session) ChannelAPI ¶ added in v0.31.0
func (s *Session) ChannelAPI() *channelapi.Requester
ChannelAPI returns a channelapi.Requester to interact with the channel package.
func (*Session) Close ¶
Close closes a websocket and stops all listening/heartbeat goroutines. If it returns an error, the session is not closed.
func (*Session) CloseWithCode ¶
CloseWithCode closes a websocket using the provided closeCode and stops all listening/heartbeat goroutines. If it returns an error, the session is not closed. TODO: Add support for Voice WS/UDP connections
func (*Session) EventManager ¶ added in v0.32.0
func (s *Session) EventManager() bot.EventManager
EventManager returns the event.Manager used by the Session.
func (*Session) ForceClose ¶ added in v0.32.0
ForceClose the connection. Use Close or CloseWithCode before to have a better closing process.
It doesn't send an event.Disconnect, unlike Close or CloseWithCode.
func (*Session) Gateway ¶
func (s *Session) Gateway(options ...discord.RequestOption) (string, error)
Gateway returns the websocket Gateway address
func (*Session) GatewayBot ¶
func (s *Session) GatewayBot(options ...discord.RequestOption) (*GatewayBotResponse, error)
GatewayBot returns the websocket Gateway address and the recommended number of shards
func (*Session) GatewayDial ¶ added in v0.32.0
func (*Session) GatewayWriteStruct ¶
func (*Session) GuildAPI ¶ added in v0.31.0
GuildAPI returns a guildapi.Requester to interact with the guild package.
func (*Session) HeartbeatLatency ¶
HeartbeatLatency returns the latency between heartbeat acknowledgement and heartbeat send.
func (*Session) InteractionAPI ¶ added in v0.31.0
func (s *Session) InteractionAPI() *interactionapi.Requester
InteractionAPI returns an interactionapi.Requester to interact with the interaction package.
func (*Session) InviteAPI ¶ added in v0.31.0
InviteAPI returns an inviteapi.Requester to interact with the invite package.
func (*Session) LastHeartbeatAck ¶
LastHeartbeatAck returns the time.Time of the last heartbeat ack received.
func (*Session) LastHeartbeatSent ¶
LastHeartbeatAck returns the time.Time of the last heartbeat sent.
func (*Session) Open ¶
Open creates a websocket connection to Discord. https://discord.com/developers/docs/topics/gateway#connecting
func (*Session) OpenAndBlock ¶ added in v0.32.1
OpenAndBlock calls Session.Open and block the program until an OS signal is received. It returns an error if Session.Open or Session.Close return an error. When this function returns, the session is already disconnected.
func (*Session) SessionState ¶ added in v0.32.0
SessionState returns the state.Bot of the Session.
func (*Session) SetStateParams ¶ added in v0.32.0
SetStateParams sets the state.Params for the state.State
type SessionInformation ¶
type SessionInformation struct {
Total int `json:"total,omitempty"`
Remaining int `json:"remaining,omitempty"`
ResetAfter int `json:"reset_after,omitempty"`
MaxConcurrency int `json:"max_concurrency,omitempty"`
}
SessionInformation provides the information for max concurrency sharding.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package application handles everything related with Discord's Application and Team.
|
Package application handles everything related with Discord's Application and Team. |
|
applicationapi
Package applicationapi contains everything to interact with everything located in the application package.
|
Package applicationapi contains everything to interact with everything located in the application package. |
|
Package bot contains everything related to the bot.
|
Package bot contains everything related to the bot. |
|
Package channel contains every data structures linked with channels like...
|
Package channel contains every data structures linked with channels like... |
|
channelapi
Package channelapi contains everything to interact with everything located in the channel package.
|
Package channelapi contains everything to interact with everything located in the channel package. |
|
Package component contains everything related to Component including Modal component and Message component.
|
Package component contains everything related to Component including Modal component and Message component. |
|
Package discord contains every object used to interact with the Discord API.
|
Package discord contains every object used to interact with the Discord API. |
|
types
Package types contains every type constant documented in the Discord API.
|
Package types contains every type constant documented in the Discord API. |
|
Package emoji contains every thing related to emoji and stickers.
|
Package emoji contains every thing related to emoji and stickers. |
|
Package event contains everything related to events emmitted by Discord.
|
Package event contains everything related to events emmitted by Discord. |
|
examples
|
|
|
airhorn
command
|
|
|
auto_moderation
command
|
|
|
autocomplete
command
|
|
|
avatar
command
|
|
|
components
command
|
|
|
context_menus
command
|
|
|
dm_pingpong
command
|
|
|
echo
command
|
|
|
modals
command
|
|
|
pingpong
command
|
|
|
scheduled_events
command
|
|
|
slash_commands
command
|
|
|
stage_instance
command
|
|
|
threads
command
|
|
|
Package guild contains every data structures linked to guilds like...
|
Package guild contains every data structures linked to guilds like... |
|
guildapi
Package guildapi contains everything to interact with everything located in the guild package.
|
Package guildapi contains everything to interact with everything located in the guild package. |
|
Package interaction contains everything linked with interactions like...
|
Package interaction contains everything linked with interactions like... |
|
interactionapi
Package interactionapi contains everything to interact with everything located in the interaction package.
|
Package interactionapi contains everything to interact with everything located in the interaction package. |
|
Package logger contains the structures used by gokord's custom slog.Logger.
|
Package logger contains the structures used by gokord's custom slog.Logger. |
|
Package premium contains everything related with premium things in your application.Application.
|
Package premium contains everything related with premium things in your application.Application. |
|
premiumapi
Package premiumapi contains everything to interact with everything located in the premium package.
|
Package premiumapi contains everything to interact with everything located in the premium package. |
|
Package state contains interfaces and variables used by every State.
|
Package state contains interfaces and variables used by every State. |
|
tools
|
|
|
cmd/eventhandlers
command
|
|
|
cmd/session
command
|
|
|
Package user contains everything related to Discord User, guild.Guild Member and Integration.
|
Package user contains everything related to Discord User, guild.Guild Member and Integration. |
|
invite
Package invite contains the Invite...
|
Package invite contains the Invite... |
|
invite/inviteapi
Package inviteapi contains everything to interact with everything located in the invite package.
|
Package inviteapi contains everything to interact with everything located in the invite package. |
|
userapi
Package userapi contains everything to interact with everything located in the user package.
|
Package userapi contains everything to interact with everything located in the user package. |
|
Package voice contains everything related to Discord voice Connection.
|
Package voice contains everything related to Discord voice Connection. |