Giter VIP home page Giter VIP logo

discord-game-sdk-godot's Introduction

Discord GameSDK Godot 4.x

Project Logo

Unofficial Discord GameSDK wrapper for Godot Engine 4.x (includes demo project)

Discord GameSDK plugin for Godot 4.x using GDExtension

Godot4   Discord GameSDK 3.1.0

Disclaimer: This project is NOT affiliated with Discord Inc nor Godot Engine. It doesn't endorse Discord GameSDK. This project and sample Godot project are provided solely for educational purposes and may or may not comply with Discord's Terms of Service and/or Privacy Policy.

Table of Contents

Features

  • ✔️ Static type support
  • ✔️ In-engine documentation
  • ✔️ Uses signals for async events
  • ✔️ Cross-platform Windows, Linux, MacOS

All features of the Discord GameSDK are supported and example provided in the sample project!

  • ✔️ User (Get current user, get user by id, etc)
  • ✔️ Activity (Update, clear, etc)
  • ✔️ Overlay (Open/close voice settings, guild invite, etc)
  • ✔️ Relationship (Load, filter, etc)

How does it work

This project uses GDExtension to wrap the Discord GameSDK C SDK so that it can be easily used in Godot using GDScript, C#, etc with similar class hierarchy, static type support and in-engine documentation. It makes use of signals for sending events like activity updated, cleared, etc.

Support the project development

It would be great if you could support the development of this project. You can do so by:

Cross-platform support

Platform Supported Tested Size in exported game
Windows x64 ✔️ ✔️ 4 MB
Linux x64 ✔️ ✔️ 8 MB
MacOS x64 ✔️ - MB

Screenshots

User

User

Overlay

Overlay

Activity

Activity

Relationship

Relationship

Installation

Pre-requisites

  • Discord application for your game (See Get set up) (You need the CLIENT_ID from Discord Developer Portal)

This is a regular plugin for Godot 4.x. To install the plugin follow the steps below:

  1. Goto the Releases section and download the latest release zip.
  2. Extract the zip file and copy the discord-game-sdk-godot folder into the res://addons/ folder of your project. If the res://addons/ folder does not exist, create one.
  3. Goto Project->Project Settings->Plugins and enable the Discord GameSDK Godot 4.x plugin by 3ddelano.
  4. You can now use the plugin. Use the below example script or open the sample project:
    # In main script
    extends Node
    
    func _ready():
        # Setup logging for Discord GameSDK
        DiscordSDK.Core.get_instance().discord_log.connect(_on_discord_log)
        
        # Initialize Discord GameSDK
        var create_res = DiscordSDK.Core.create("YOUR_CLIENT_ID_HERE", DiscordSDK.Core.CreateFlags.NoRequireDiscord)
        if DiscordSDK.is_error(create_res):
            print("Failed to create Discord GameSDK: Got result %s" % DiscordSDK.result_str(create_res))
            return
        
        print("Initialzized Discord GameSDK!")
        # Now you can use the Discord GameSDK
        # See the sample project for examples
    
    func _on_discord_log(log_msg: DiscordLogData):
        print(str(log_msg.level) + " | " + log_msg.message)

Development Setup

Pre-requisites

To develop this plugin locally, follow the below steps:

  1. Clone / Download the repository.

  2. Extract the Discord GameSDK zip downloaded from Discord Developer Portal, rename it to discord_game_sdk and paste it in the thirdparty/ folder. Refer to the below folder structure.

    Folder Structure

  3. Follow the steps to generate the GDExtension bindings for C++ based on this tutorial. After this you should have built the godot-cpp library successfully.

  4. Run the setup script

    python3 setup.py
  5. Build the GDExtension plugin in debug mode (With debug symbols)

    # In root folder
    scons platform=<platform> target=template_debug dev_build=yes

    Eg. scons platform=windows target=template_debug dev_build=yes

  6. Build the GDExtension plugin for release (Optimized)

    # In root folder
    scons platform=windows target=template_release dev_build=no

    Eg. scons platform=windows target=template_release dev_build=no

  7. The built GDExtension library files will be in the addons/discord-game-sdk-godot/bin/ folder.

How to run the sample project?

The sample Godot project is located in the /sample folder

  1. Clone / Download the repository.
  2. Delete the existing addons/discord-game-sdk-godot folder in the project.
  3. Download the latest release of the plugin from the Releases section. Then copy the discord-game-sdk-godot folder from the downloaded zip into the addons/ folder of the sample project.
  4. Ensure that the Discord GameSDK Godot 4.x plugin is enabled in Project->Project Settings->Plugins.
  5. Ensure that the Discord desktop application is open.
  6. Run the Main.tscn scene.

Documentation

The entire documentation is available in the in-engine documentation. To view this, press F1 in the Godot Editor. Now in the popup window, search for any of the plugin's classes and view its documentattion.

Classes

  • DiscordSDK
  • DiscordSDK.Core
  • DiscordSDK.User
  • DiscordSDK.Activity
  • DiscordSDK.Relationship
  • DiscordSDK.Overlay

IMPORTANT: Whenever you connect to a signal of Discord GameSDK always connect it on the get_instance() object and not on the class itself.

Example

# This is correct way
DiscordSDK.Core.get_instance().discord_log.connect(_on_discord_log)
DiscordSDK.Core.get_instance().connect("discord_log", Callable(self, "_on_discord_log"))
DiscordSDK.Activity.get_instance().update_activity_cb.connect(_on_update_activity_cb)
# This is wrong way
DiscordSDK.Core.discord_log.connect(_on_discord_log)
DiscordSDK.Core.connect("discord_log", Callable(self, "_on_discord_log"))
DiscordSDK.Activity.update_activity_cb.connect(_on_update_activity_cb)

Also do not directly use classes that start with IDGS such as IDGSCore, IDGSUser, etc.

discord-game-sdk-godot's People

Contributors

3ddelano avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.