session

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: ISC Imports: 6 Imported by: 6

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

Constants

This section is empty.

Variables

View Source
var ErrMFA = errors.New("account has 2FA enabled")

Functions

This section is empty.

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.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 Login

func Login(email, password, mfa string) (*Session, error)

Login tries to log in as a normal user account; MFA is optional.

func New

func New(token string) (*Session, error)

New creates a new session from a given token. Most bots should be using NewWithIntents instead.

func NewWithGateway

func NewWithGateway(gw *gateway.Gateway) *Session

func NewWithIntents

func NewWithIntents(token string, intents ...gateway.Intents) (*Session, error)

func (*Session) Close

func (s *Session) Close() error

Close closes the gateway. The connection is still resumable with the given session ID.

func (*Session) CloseGracefully added in v2.0.2

func (s *Session) CloseGracefully() error

CloseGracefully permanently closes the gateway. The session ID is invalidated afterwards.

func (*Session) Open

func (s *Session) Open() error

func (*Session) WithContext

func (s *Session) WithContext(ctx context.Context) *Session

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL