Methods
A Client
object has the following methods.
setScopes(scopes)
chainable
Set the scopes for future requests
Parameters
- scopes [ Scope|Array.<Scope> ] :: The list of scopes that the user will authorize.
Example
myClient.setScopes('identify', 'guilds');
myClient.setScopes(['identify', 'email', 'connections']);
setRedirect(redirectUri)
chainable
Set the redirect URI for future requests.
Parameters
- redirectUri [ string ] :: One of the redirect URI from discord application settings.
Example
myClient.setRedirect('http://localhost:3000/login');
getAccess(code)
async
Gets the access token for the user to perform further functions.
Parameters
- code [ string ] :: The authorization code returned by discord after the authentication.
Returns
-
[ Promise.<string> ] :: The user key that will be used to fetch the user's data.
Example
let userKey = myClient.getAccess(req.query.code);
raw(key)
async
Converts the user's key into the access token response sent by discord. Not recommended to use.
Parameters
- key [ string ] :: The user's key which needs to be converted into the access token response.
Returns
-
[ Promise.<object> ] :: tokenResponse The access token response returned by the discord for the user.
Example
let tokenResponse = myClient.raw(userKey);
checkValidity(key)
async
Checks the validity of the access key.
Parameters
- key [ string ] :: The user key whose validity is to be checked.
Returns
-
[ Object ] :: The validity data of the user key.
Example
let validityData = myClient.checkValidity(myUserKey);
refreshToken(key)
async
Gets a new access token for the user whose access token has expired.
Parameters
- key [ string ] :: The user key of the user whose access token is to be refreshed.
Returns
-
[ Promise.<string> ] :: The new user key.
Example
let newKey = myClient.refreshToken(oldUserKey);
getUser(key)
async
Gets the user whose user key is provided from the discord API.
Parameters
- key [ string ] :: The user key of the user whose data is to be fetched.
Returns
-
[ Promise.<User> ] :: The returned user.
Example
let myFavUser = myClient.getUser(userKey);
getGuilds(key)
async
Gets the guilds of the user whose user key is provided from the discord API.
Parameters
- key [ string ] :: The user key of the user whose guilds are to be fetched.
Returns
-
[ Promise.<Guilds> ] :: The returned guilds.
Example
let myFavGuilds = myClient.getGuilds(userKey);
getConnections(key)
async
Gets the connected third-party accounts of the user whose user key is provided from the discord API.
Parameters
- key [ string ] :: The user key of the user whose connections are to be fetched.
Returns
-
[ Promise.<Connections> ] :: The returned connections.
Example
let myFavConnections = myClient.getConnections(userKey);