Documentation ¶
Overview ¶
Package discord implements an HTTP API client for OAuth2 flow.
Index ¶
- Variables
- func NewAPIError(res *http.Response) error
- type AddGuildMemberOption
- func WithAccessToken(at string) AddGuildMemberOption
- func WithBotToken(bt string) AddGuildMemberOption
- func WithDeaf(d bool) AddGuildMemberOption
- func WithGuildID(id string) AddGuildMemberOption
- func WithMute(m bool) AddGuildMemberOption
- func WithNick(n string) AddGuildMemberOption
- func WithRoles(r ...string) AddGuildMemberOption
- func WithUserID(id string) AddGuildMemberOption
- type Client
- func (c *Client) AddGuildMember(ctx context.Context, opts ...AddGuildMemberOption) (*discord.GuildMember, error)
- func (c *Client) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
- func (c *Client) Do(ctx context.Context, opts ...RequestOption) ([]byte, error)
- func (c *Client) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (c *Client) User(ctx context.Context, token string) (*discord.User, error)
- func (c *Client) UserGuilds(ctx context.Context, token string) ([]*discord.PartialGuild, error)
- type Error
- type Option
- type RequestOption
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 (*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) 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) UserGuilds ¶
UserGuilds fetches the current user's guilds. Requires the guilds scope.
type Error ¶
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient sets a Client's HTTP client. Defaults to http.DefaultClient.
func WithOAuth2Config ¶
WithOAuth2Config sets a Client's OAuth2 config.
type RequestOption ¶
type RequestOption func(*request)
RequestOption configures an HTTP request.
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.