Documentation ¶
Overview ¶
Package session abstracts around the REST API and the Gateway, managing both at once. It offers a handler interface similar to that in discordgo for Gateway events.
Index ¶
- Variables
- func NewShardFunc(f func(m *shard.Manager, s *Session)) shard.NewShardFunc
- type Closed
- type Session
- func Login(email, password, mfa string) (*Session, error)
- func New(token string) (*Session, error)
- func NewCustomSession(gw *gateway.Gateway, cl *api.Client, h *handler.Handler) *Session
- func NewCustomShard(m *shard.Manager, id *gateway.Identifier) *Session
- func NewWithGateway(gw *gateway.Gateway) *Session
- func NewWithIntents(token string, intents ...gateway.Intents) (*Session, error)
Constants ¶
This section is empty.
Variables ¶
var ErrMFA = errors.New("account has 2FA enabled")
Functions ¶
func NewShardFunc ¶
func NewShardFunc(f func(m *shard.Manager, s *Session)) shard.NewShardFunc
NewShardFunc creates a shard constructor for a session.
Types ¶
type Closed ¶
type Closed struct {
Error error
}
Closed is an event that's sent to Session's command handler. This works by using (*Gateway).AfterClose. If the user sets this callback, no Closed events would be sent.
Usage
ses.AddHandler(func(*session.Closed) {})
type Session ¶
type Session struct { *api.Client *gateway.Gateway // Command handler with inherited methods. *handler.Handler // contains filtered or unexported fields }
Session manages both the API and Gateway. As such, Session inherits all of API's methods, as well has the Handler used for Gateway.
func New ¶
New creates a new session from a given token. Most bots should be using NewWithIntents instead.
func NewCustomSession ¶
NewCustomSession constructs a bare Session from the given parameters.
func NewCustomShard ¶
func NewCustomShard(m *shard.Manager, id *gateway.Identifier) *Session
NewCustomShard creates a new session from the given shard manager and other parameters.
func NewWithGateway ¶
NewWithGateway creates a new Session with the given Gateway.
func NewWithIntents ¶
func (*Session) Close ¶
Close closes the underlying Websocket connection, invalidating the session ID.
It will send a closing frame before ending the connection, closing it gracefully. This will cause the bot to appear as offline instantly.
func (*Session) Pause ¶
Pause pauses the Gateway connection, by ending the connection without sending a closing frame. This allows the connection to be resumed at a later point.
func (*Session) WithContext ¶
WithContext returns a shallow copy of Session with the context replaced in the API client. All methods called on the returned Session will use this given context.
This method is thread-safe only after Open and before Close are called. Open and Close should not be called on the returned Session.