A simple library to lighten and quicken the use of discord's oauth2
Lets get started with using OAuth-cord!
First we require the oauth-cord
package. Then create a new instance of a Client
which gives us access to multiple methods!
const OAuthCord = require("oauth-cord");
const client = new OAuthCord.Client();
Next we need to tell our client
some things like a redirctUrl
and some scopes
.
const OAuthCord = require("oauth-cord");
const client = new OAuthCord.Client();
client.setRedirect("http://localhost:8080/login"); // Sets for URL to redirect to after authorizing
client.setScopes(["identitfy", "guilds"]); // Set the scopes
Now we get to the fun part!
When you authorize the app you will get a code. You use that code to get an access token. Note: this method is async so use we use await here.
const token = await client.getToken(code); // pass code as param
This method lets us get basic user info! Note: If you add the email scope you will also get the users email in the user object.
const token = await client.getToken(code);
client.getUser(token); // set token you got as a param
Use this to get a list of a users profile connections.
const token = await client.getToken(code);
client.getUserConnections(token);
This method returns the guilds a user is in.
const token = await client.getToken(code);
client.getUserGuilds(token);
Adds a user to a choosen guild! Note: You need to create bot for your discord app and have it in the server your trying to invite users to with the "CREATE_INSTANT_INVITE" permission for this to work.
const token = await client.getToken(code);
client.addUserGuild(token, botToken, serverId);
// pass token, botToken, and serverId are params
And thats it! Thats all the methods for now.
Feel free to contribute to this project by opening a pull request on github. If you have any sugestions or issues open up a issue on github!
Bye!