1.1.2 • Published 2 years ago

discord-oauth2-api v1.1.2

Weekly downloads
7
License
ISC
Repository
github
Last release
2 years ago

Discord Oauth2 API

Library for interacting with Discord Oauth2 API

Installation

$ npm i discord-oauth2-api

Constructor

Usage

new Client(options)

options.clientID - Your application client ID

options.clientSecret - Your application client secret

options.scopes - Array of Oauth2 scopes

options.redirectURI - Your Oauth2 redirect URI

Example

const Client = require('discord-oauth2-api');
const client = new Client({
    clientID: '665555588004053002',
    clientSecret: 'Z2EkOCKCwr4f6BhCjJ3jGWPZOk7RaRpK',
    scopes: ['identify', 'guilds'],
    redirectURI: 'http://localhost:3000/login'
});

Get Access Token

Usage

client.getAccessToken(code)

code - Your query code

Returns: Promise<Token>

Example

client.getAccessToken('8kYuLrkA7KXKYwJDIHpgpVYCKAIqUC').then(token => console.log(token.accessToken));
// OwxOnwxbAMzsa8ZE9ugYQk5feIJL6K

Get User

Usage

client.getUser(accessToken)

accessToken - Oauth2 access token

Returns: Promise<User>

Example

client.getUser('OwxOnwxbAMzsa8ZE9ugYQk5feIJL6K').then(user => console.log(user.tag));
// 🚀!SMOKY PLAY!🚀#1050

Get User Guilds

Usage

client.getGuilds(accessToken)

accessToken - Oauth2 access token

Returns: Promise<Array<Guild>>

Example
client.getUser('OwxOnwxbAMzsa8ZE9ugYQk5feIJL6K').then(guilds => console.log(guilds[0].name))
// Cool Server

Refresh Token

Usage

client.refreshToken(refreshToken)

refreshToken - Oauth2 refresh token

Returns: Promise<Token>

Example
client.refreshToken('afzGuTtQI9hhXY4rhMP7lp7RCyaT0C').then(token => console.log('New access token: ' + token.accessToken))
// New access token: ANawRpft7SNOcibq7HLLfCA8rGQ0bp

Revoke Token

Usage

client.revokeToken(token)

token - Oauth2 access token

Returns: Promise<Token> (token is null)

Example
client.revokeToken('afzGuTtQI9hhXY4rhMP7lp7RCyaT0C').then(token => console.log('Access token successfully revoked!'))
// New access token: ANawRpft7SNOcibq7HLLfCA8rGQ0bp

Classes

Token

PropertyTypeExampleDescription
accessTokenString'OwxOnwxbAMzsa8ZE9ugYQk5feIJL6K'Oauth2 access token
expiresInNumber604800Time in seconds, after which the token will become invalid
refreshTokenString'afzGuTtQI9hhXY4rhMP7lp7RCyaT0C'Token, that is used to refresh access token
scopesArray'identify', 'guilds'Oauth2 scopes
tokenTypeString'Bearer'Type of token

User

PropertyTypeExampleDescription
idString'591321756799598592'User ID
usernameString'🚀!SMOKY PLAY!🚀'User username
discriminatorString'1050'User's 4 digits after #
tagString'🚀!SMOKY PLAY!🚀#1050'User username with 4 digits after #
avatarString'a_21575f7072eba9af0e6b5255b219296f'User avatar hash
emailString'example@gmail.com'User enail address (available if the user granted access)
verifiedBooleantrueWhether the user email has been verified
MFAEnabledBooleanfalseWhether the user has two factor enabled
localeString'ru'The user's chosen language option
flagsNumber131328User's flags
premiumTypeNumber1The type of user's Nitro subscription
Methods

avatarURL(options)

options.size - avatar size

options.format - avatar format: png, jpg, webp or gif

options.dynamic - animated (true/false)

Returns: AvatarURL

Guild

PropertyTypeExampleDescription
idString'629712997849367400'Guild ID
nameString'Cool Server'Server name
iconString'afec5e0a86a89bd20b8e87402a31eac4'Guild icon hash
isOwnerBooleantrueWhether the user is an owner of this guild
permissionsNumber104189504User permissions on this guild
featuresArray 'COMMUNITY', 'NEWS' Array of guild features
Methods

iconURL(options)

options.size - icon size

options.format - icon format: png, jpg, webp or gif

options.dynamic - animated (true/false)

Returns: IconURL

1.1.2

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago