discord

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 7 Imported by: 0

README

Discord

An API client that implements Discord's OAuth2 flow.

License

MIT

Documentation

Overview

Package discord partially implements Discord's HTTP API to streamline the OAuth2 flow for consumers.

Index

Constants

View Source
const (
	Version = "v0.1.0"
)

Variables

View Source
var (
	// Endpoint is Discord's API endpoint for OAuth2.
	Endpoint = oauth2.Endpoint{
		AuthURL:  "https://discord.com/api/oauth2/authorize",
		TokenURL: "https://discord.com/api/oauth2/token",
	}

	// ErrMissingRequiredArgument is returned when a required argument is missing
	ErrMissingRequiredArgument = errors.New("discord: missing a required argument")
)

Functions

This section is empty.

Types

type Discord

type Discord struct {
	// contains filtered or unexported fields
}

Discord is an API client.

func New

func New(opts ...Option) (*Discord, error)

New creates a new Discord client.

func (*Discord) AuthCodeURL

func (d *Discord) AuthCodeURL(state string) string

AuthCodeURL returns a URL to authenticate a user with.

func (*Discord) Exchange

func (d *Discord) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

Exchange performs an OAuth2 exchange.

func (*Discord) GuildsFromToken added in v0.3.0

func (d *Discord) GuildsFromToken(ctx context.Context, token string) ([]*Guild, error)

GuildsFromToken fetches the list of Guilds a Discord user belongs to. Requires the `guilds` OAuth2 scope.

func (*Discord) UserFromToken

func (d *Discord) UserFromToken(ctx context.Context, token string) (*User, error)

UserFromToken gets a Discord User from an OAuth token.

type Error

type Error struct {
	HTTPStatus int    `json:"-"`
	Code       int    `json:"code"`
	Message    string `json:"message"`
}

Error is an error returned from the Discord API. It implements the Error interface.

func (*Error) Error

func (e *Error) Error() string

type Guild added in v0.3.0

type Guild struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	IconHash    string   `json:"icon"`
	Owner       bool     `json:"owner"`
	Permissions string   `json:"permissions"`
	Features    []string `json:"features"`
}

Guild is a partial guild that the authenticated user belongs to.

func (*Guild) Icon added in v0.3.0

func (g *Guild) Icon() string

Icon returns the URL to a Guild's icon.

type Option

type Option func(*Discord)

Option configures a Discord.

func WithHTTPClient

func WithHTTPClient(cli *http.Client) Option

WithHTTPClient specifies the *http.Client to use.

func WithOAuth2Config

func WithOAuth2Config(conf *oauth2.Config) Option

WithOAuth2Config specifies the *oauth2.Config to use.

type User

type User struct {
	ID            string `json:"id"`
	Username      string `json:"username"`
	Discriminator string `json:"discriminator"`
	AvatarHash    string `json:"avatar"`
	Bot           bool   `json:"bot,omitempty"`
	System        bool   `json:"system,omitempty"`
	MFAEnabled    bool   `json:"mfa_enabled,omitempty"`
	Locale        string `json:"locale,omitempty"`
	Flags         int    `json:"flags,omitempty"`
	PremiumType   int    `json:"premium_type,omitempty"`
	PublicFlags   int    `json:"public_flags,omitempty"`
}

User is a partial definition of a Discord User defined by the API.

func (*User) Avatar

func (u *User) Avatar() string

Avatar returns a URL to the User's avatar, in PNG format.

Jump to

Keyboard shortcuts

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