discord

package module
v0.0.0-...-af29261 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 12 Imported by: 0

README

discord

A Discord API client modeled for use with Bearer tokens, rather than Bot; this client is strictly for the HTTP REST API, there is no gateway code involved.

License

MIT

Documentation

Overview

Package discord implements an HTTP API client for OAuth2 flow.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Endpoint is an oauth2.Endpoint specifically for Discord.
	Endpoint = oauth2.Endpoint{
		AuthURL:   "https://discord.com/api/oauth2/authorize",
		TokenURL:  "https://discord.com/api/oauth2/token",
		AuthStyle: oauth2.AuthStyleAutoDetect,
	}

	// ErrMissingOption is returned when a required option is missing.
	ErrMissingOption = errors.New("discord: missing required option")
	ErrInvalidParam  = errors.New("discord: invalid request parameter")
)

Functions

func NewAPIError

func NewAPIError(res *http.Response) error

Types

type AddGuildMemberOption

type AddGuildMemberOption func(*addGuildMemberParams)

func WithAccessToken

func WithAccessToken(at string) AddGuildMemberOption

func WithBotToken

func WithBotToken(bt string) AddGuildMemberOption

func WithDeaf

func WithDeaf(d bool) AddGuildMemberOption

func WithGuildID

func WithGuildID(id string) AddGuildMemberOption

func WithMute

func WithMute(m bool) AddGuildMemberOption

func WithNick

func WithNick(n string) AddGuildMemberOption

func WithRoles

func WithRoles(r ...string) AddGuildMemberOption

func WithUserID

func WithUserID(id string) AddGuildMemberOption

type Client

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

func New

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

New creates a new client, ready to use.

func (*Client) AddGuildMember

func (c *Client) AddGuildMember(ctx context.Context, opts ...AddGuildMemberOption) (*discord.GuildMember, error)

AddGuildMember adds a Discord user to a guild. The returned GuildMember may be nil.

func (*Client) AuthCodeURL

func (c *Client) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string

AuthCodeURL returns the authorization URL for the client's oauth2 config.

func (*Client) Do

func (c *Client) Do(ctx context.Context, opts ...RequestOption) ([]byte, error)

Do makes a request against Discord's API.

func (*Client) Exchange

func (c *Client) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)

Exchange converts an authorization code into a token.

func (*Client) User

func (c *Client) User(ctx context.Context, token string) (*discord.User, error)

User fetches the current User from Discord's API.

func (*Client) UserGuilds

func (c *Client) UserGuilds(ctx context.Context, token string) ([]*discord.PartialGuild, error)

UserGuilds fetches the current user's guilds. Requires the guilds scope.

type Error

type Error struct {
	HTTPCode int
	Code     int                    `json:"code"`
	Errors   map[string]interface{} `json:"errors,omitempty"`
	Message  string                 `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type Option

type Option func(*Client)

Option configures a Client.

func WithHTTPClient

func WithHTTPClient(cli *http.Client) Option

WithHTTPClient sets a Client's HTTP client. Defaults to http.DefaultClient.

func WithOAuth2Config

func WithOAuth2Config(conf *oauth2.Config) Option

WithOAuth2Config sets a Client's OAuth2 config.

type RequestOption

type RequestOption func(*request)

RequestOption configures an HTTP request.

func WithBody

func WithBody(b io.Reader) RequestOption

WithBody sets a request's body.

func WithHeaders

func WithHeaders(h map[string]string) RequestOption

WithHeaders sets a request's headers.

func WithMethod

func WithMethod(m string) RequestOption

WithMethod sets a request's HTTP method. Defaults to HTTP GET.

func WithQuery

func WithQuery(q url.Values) RequestOption

WithQuery sets a request's query params.

func WithToken

func WithToken(t string) RequestOption

WithToken sets a request's bearer token.

func WithURL

func WithURL(u string) RequestOption

WithURL sets a request's API URI.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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