-
Notifications
You must be signed in to change notification settings - Fork 6
Getting Started
Kayra Uylar edited this page Jul 4, 2024
·
5 revisions
- To use this SDK, copy the correct DiscordSDK.gd file to your project.
- In Project Settings, add the script as an AutoLoad script.
- In your scripts, call
DiscordSDK.init("YOUR_CLIENT_ID")in_ready() - Wait for the
dispatch_readyevent to be fired.- If this event isn't firing, then your client ID might be wrong.
- Call
DiscordSDK.command_authorize("code", ["list", "of", "oauth2", "scopes", "you", "want", "to", "use"], "")- All functions prefixed with
command_are async functions. Make sure to yield/await them!
- All functions prefixed with
- Do the OAuth flow with the code you received from the function call
- In the example code, an endpoint named
/api/authis used. This endpoint is neither included by Discord or Godot. You must implement the server-side part of the OAuth flow and point your code to call that endpoint.
- In the example code, an endpoint named
- Call
DiscordSDK.command_authenticate("OAUTH2_ACCESS_TOKEN_YOU_GOT_FROM_YOUR_BACKEND") - Everything should be working now! Except signals. Call
DiscordSDK.subscribe_to_events()to get all dispatch events indispatch_*signals.- You have to call this function after the authentication flow. Otherwise you will get unauthorized errors
Note
While loading your export in Discord, make sure to load the exported HTML directly. Putting it in an iframe WILL break functionality
Warning
Note that due to strict CORS limitations, your client can only connect to https://<client-id>.discordsays.com. See more about URL mappings here
Fun fact: This repository also works as a sample project! You can load it directly inside Godot