npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

discord-oauth2-api

v1.1.2

Published

Library for Discord Oauth2 API

Downloads

141

Readme

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

| Property | Type | Example | Description | | --- | --- |--- | --- | | accessToken | String | 'OwxOnwxbAMzsa8ZE9ugYQk5feIJL6K' | Oauth2 access token | | expiresIn | Number | 604800 | Time in seconds, after which the token will become invalid | | refreshToken | String | 'afzGuTtQI9hhXY4rhMP7lp7RCyaT0C' | Token, that is used to refresh access token | | scopes | Array | ['identify', 'guilds'] | Oauth2 scopes | | tokenType | String | 'Bearer' | Type of token |

User

| Property | Type | Example | Description | | --- | --- |--- | --- | | id | String | '591321756799598592' | User ID | | username | String | '🚀!SMOKY PLAY!🚀' | User username | | discriminator | String | '1050' | User's 4 digits after # | | tag | String | '🚀!SMOKY PLAY!🚀#1050' | User username with 4 digits after # | | avatar | String | 'a_21575f7072eba9af0e6b5255b219296f' | User avatar hash | | email | String | '[email protected]' | User enail address (available if the user granted access) | | verified | Boolean | true | Whether the user email has been verified | | MFAEnabled | Boolean | false | Whether the user has two factor enabled | | locale | String | 'ru' | The user's chosen language option | | flags | Number | 131328 | User's flags | | premiumType | Number | 1 | The 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

| Property | Type | Example | Description | | --- | --- |--- | --- | | id | String | '629712997849367400' | Guild ID | | name | String | 'Cool Server' | Server name | | icon | String | 'afec5e0a86a89bd20b8e87402a31eac4' | Guild icon hash | | isOwner | Boolean | true | Whether the user is an owner of this guild | | permissions | Number | 104189504 | User permissions on this guild | | features | Array | [ '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