A simple plugin to connect discord to a site/app/game/etc.
Warning
This plugin is currently using the Implicit Grant workflow ofOAuth2
.
This simply means theClient(Browser)
is directly being given anaccess_token
rather than anaccess_code
. In a standardOAuth2
workflow thataccess_code
would be passed to the server and the server would queryDiscord
using thataccess_code
to verify the user on theServer-Side
rather thanClient-Side
. Using theImplicit Grant
workflow, means it skips theserver
entirely.
In this workflow all data is passed directly to theClient
. In this case, the data is the User Object.
Note
In the future more workflows will be allowed and will be defaulted to as the standard.
Such as the Authorization Code Grant as well as the Client Credentials Grant.
These will allow for more personalized workflows for different games/applications.
These will also allow the server to act as an intermediary, so that data doesn't have to actually be passed directly to theClient
If this workflow is an issue with security, then it is advised to not use it in it's current state. And to rather wait for the aforementioned workflows to be added.
Head over to https://discord.com/developers/applications
Once you have your Client ID
keep it nearby for later.
We now need to add a few redirects to our discord app, so it knows where to go.
These redirects are official Domain/IPs that are trusted within this application. Such as your site/app/game/etc.
Note
If you have many servers, add each Domain/IP.
These redirects also work with local hosting!
You will need to supply your Client ID
inside of discord-linked.js
Open the discord-linked.js
file, and find the declaration of CLIENT_ID
and input your Client ID
value inside the empty string.
If you would like this plugin to automatically authenticate ASAP, then open the discord-linked.js
file, and find the declaration of AUTO_AUTH
and input the value true
It is false by default.
If you do not want to automatically authenticate, then you will need to use DiscordHandler.login()
.
When connecting to a game, users will be prompted to login via discord if they are not already logged in, and will be prompted to authorize your discord app to use their data.
Upon authorization, the site/app/game/etc will load.
Note
Outside of Vylocity, just include the script into the project files.
window.DiscordUser | DiscordUser JavaScript
DiscordUser VyScript
window.DiscordHandler | DiscordHandler JavaScript
DiscordHandler VyScript
description
: An instanced object that handles the authentication process of a discord user
description
: An instanced object that holds all data related to the authenticated discord user
description
: Callable API to start the authentication process of a discord user (If usingAUTO_AUTH
this is already called for you)
returns
: Returns the id of the logged in discord user
returns
: Returns the username of the logged in discord user
returns
: Returns the avatar hash of the logged in discord user
returns
: Returns the banner hash of the logged in discord user
returns
: Returns the banner color of the logged in discord user
returns
: Returns the accent color of the logged in discord user
returns
: Returns the nitro membership of the logged in discord user
0: None 1: Nitro Classic 2: Nitro
returns
: Returns if the logged in discord user has 2fa enabled
returns
: Returns the tag of the logged in discord user
returns
: Returns the public flags on the logged in discord user's account
returns
: Returns if the logged in discord user is a bot
returns
: Returns if the logged in discord user has verified their email address
pWidth
: The width to make the discord avatar iconpHeight
: The height to make the discord avatar iconpCallback
: A callback function that will be called when this icon is readydescription
: Inside of the callback, the icon will be ready to be used. TheatlasName
will be theid
ofDiscordUser
and theiconName
will be the static name ofavii