Launch
There is situations where you want Discord to launch your game. For example, when you accept your friend invite to play the game.
To solve that, you need to register inside Discord client how to launch your game (at least once).
Tip
It's recommended to do that as soon as possible (e.g. when the game open).
Launch Command
Give to Discord the command to run to start your game:
func _ready() -> void:
client.register_launch_command(application_id, "/path/for/the/game/executable")
Runtime
We never know where the user will install the executable, so you should use some logic to find out. For example, registering the executable path at runtime:
func _ready() -> void:
client.register_launch_command(
application_id,
ProjectSettings.globalize_path((OS.get_executable_path()),
)
In this case, ProjectSettings.globalize_path() is used to convert to the correct OS style path.
Warning
During development (inside Godot Editor) the OS.get_executable_path() will result in the Godot executable path. Which would make Discord open Godot instead of your game.
Deep Link
Another option is to use deep link (also knows as custom URI scheme in desktops):
func _ready() -> void:
client.register_launch_command(application_id, "yourgame://")
Launch Steam Game
In case your game was installed through Steam, Discord knows how to make Steam launch your game just by using the Steam App ID.
func _ready() -> void:
client.register_launch_steam_application(application_id, steam_app_id)
References
Note
Is not possible to unregister a command through the SDK.
In Windows, open Registry Editor and delete the registry at:
Computer\HKEY_CURRENT_USER\Software\Classes\discord-APPLICATION_ID