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
- type Session
- func Login(ctx context.Context, email, password, mfa string) (*Session, error)
- func New(token string) *Session
- func NewCustom(id gateway.Identifier, cl *api.Client, h *handler.Handler) *Session
- func NewWithGateway(g *gateway.Gateway, h *handler.Handler) *Session
- func NewWithIdentifier(id gateway.Identifier) *Session
- func NewWithIntents(token string, intents ...gateway.Intents) *Session
Constants ¶
This section is empty.
Variables ¶
var ErrMFA = errors.New("account has 2FA enabled")
ErrMFA is returned if the account requires a 2FA code to log in.
Functions ¶
This section is empty.
Types ¶
type Session ¶
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 NewWithGateway ¶
NewWithGateway constructs a bare Session from the given UNOPENED gateway.
func NewWithIdentifier ¶
func NewWithIdentifier(id gateway.Identifier) *Session
NewWithIdentifier creates a bare Session with the given identifier.
func NewWithIntents ¶
NewWithIntents is similar to New but adds the given intents in during construction.
func (*Session) AddIntents ¶
AddIntents adds the given intents into the gateway. Calling it after Open has already been called will result in a panic.
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. To prevent this behavior, change Gateway.AlwaysCloseGracefully.
func (*Session) Gateway ¶
Gateway returns the current session's gateway. If Open has never been called or Session was never constructed with a gateway, then nil is returned.
func (*Session) HasIntents ¶
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 (*Session) Open ¶
Open opens the Discord gateway and its handler, then waits until either the Ready or Resumed event gets through.
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.