A Python wrapper around Discord's Game SDK.
NOTE: This is entirely experimental, and may not work as intended. Please report all bugs to the GitHub issue tracker.
Credit to NathaanTFM for creating the original library and LennyPhoenix for upgrading old project.
- Install the module:
- With
PIP
:- Latest:
python -m pip install --target /project_root/game git+https://github.com/valery-iwanofu/py-discord-sdk.git
- Latest:
- With
setup.py
:git clone https://github.com/valery-iwanofu/py-discord-sdk.git
cd py-discord-sdk
python -m setup install --target /project_root/game .
- Direct download:
- With
- Download Discord Game SDK (2.5.6).
- Grab the DLL from
discord_game_sdk.zip
in thelib
directory and put it in your project's root directory.
- Import
discordsdk
module - Initialize sdk library using
discordsdk.sdk.init_sdk(basedir)
- Create
Discord
instance and store it somewhere - Run periodic callbacks of
Discord
instance somewhere(generally, it can be done inconfig.periodic_callbacks
)
import discordsdk as dsdk
dsdk.sdk.init_sdk(config.basedir)
discord = dsdk.Discord(APPLICATION_ID, dsdk.CreateFlags.default)
def __discord_periodic_callback():
discord.run_callbacks()
config.periodic_callbacks.append(__discord_periodic_callback)
Add this lines of code to your project build configuration:
init python:
build.early_base_patterns.insert(0, ('discord_game_sdk.dll', build.make_file_lists('windows')))
build.early_base_patterns.insert(0, ('discord_game_sdk.so', build.make_file_lists('linux')))
build.early_base_patterns.insert(0, ('discord_game_sdk.dylib', build.make_file_lists('mac')))
If you need documentation, look at the official Game SDK docs; this was made following the official documentation. We also have some work-in-progress wiki docs.
-
Should be working:
- ActivityManager
- ImageManager
- NetworkManager
- RelationshipManager
- StorageManager
- UserManager
-
Should be working, but need more testing:
- AchievementManager (not tested at all)
- ApplicationManager (especially the functions
GetTicket
andValidateOrExit
) - LobbyManager
- OverlayManager
- StoreManager (not tested at all)
- VoiceManager
The code needs more comments, type hinting. You can also implement the missing features, or add more tests. Feel free to open a pull request!
You can also report issues. Just open an issue and I will look into it!
- Better organisation of submodules.
- CI/CD.
- Update sdk.py to use type annotations.
- Update to Discord SDK 3.2.0.
You can find more examples in the examples/
directory.
discord = # see how to create discord instance above
user_manager = discord.get_user_manager()
def on_curr_user_update():
user = user_manager.get_current_user()
print(f"Current user : {user.username}#{user.discriminator}")
user_manager.on_current_user_update = on_curr_user_update
discord = # see how to create discord instance above
activity_manager = discord.get_activity_manager()
activity = dsdk.Activity()
activity.state = "Testing Game SDK"
activity.party.id = "my_super_party_id"
activity.party.size.current_size = 4
activity.party.size.max_size = 8
activity.secrets.join = "my_super_secret"
def callback(result):
if result == dsdk.Result.ok:
print("Successfully set the activity!")
else:
raise Exception(result)
activity_manager.update_activity(activity, callback)