Rich Presence for Defold games on Discord
https://discordapp.com/developers/docs/rich-presence/how-to
The minimum you should do is initialize the module, then call update_presence()
whenever you want to change the user's Defold status.
This discord_client_id must be set as a string, like: "8674360155089048561"
discordrich.initialize(your_discord_client_id)
discordrich.update_presence({
status = "My status",
details = "Doing something important in-game",
})
The game will bundle fine, but in order for DiscordRich to be available when running from the editor, an extra step is required.
Copy the discordrich/res
directory from this repo to a directory in your project
and add the path to that directory to your game.project
:
[discordrich]
lib_path = path/to/discordrich/res
This module should have 1-to-1 bindings to the official C Discord RPC. All
identifiers have been converted to snake_case
.
Read the official How To Guide to understand how to use these APIs.
Initializes Discord RPC.
application_id
: Your client_id/application_idhandlers
: Optional. A table of callback functions you registered for each Discord eventauto_register
: Optional. Defaulttrue
. Whether or not to register an application protocol for your game on the player's computer. Necessary to launch games from Discordoptional_steam_id
: Optional. Your game's Steam application id, if your game is distributed on Steam. Used for launching your game through Steam ifauto_register
istrue
.
Shuts down the Discord RPC connection. There's no need to call this manually. It will get called automatically, if needed, when the game exits.
Sets your Discord presence. See
the available fields
in the official documentation. The fields have been renamed to conform
to snake_case
. (eg. largeImageText
-> large_image_text
)
Clears your Discord presence.
All of the following callbacks are optional:
Called when the game successfully connects to the Discord client. user
is a
table describing the currently logged in user:
{
user_id = "123456789012345678",
username = "AwesomeGamer",
avatar = "0123456789abcdef01234567890abcde",
discriminator = "1234"
}
Called when the game disconnects from the Discord client. A numeric errcode
and a string message
are provided describing the reason.
Called when the Discord RPC API raises an error. A numeric errcode
and a string message
are provided describing the error.
Called when the game launches as a result of the user clicking "Join" on another
player's invitation. join_secret
is the string provided to
discordrich.update_presence()
by the inviting player's game.
Called when the game launches as a result of the user clicking "Spectate" on another
player's invitation. spectate_secret
is the string provided to
discordrich.update_presence()
by the inviting player's game.
Called when another user
clicks "Ask to Join" on the current user's profile.
This is when your game should ask the user if he wants to accept the request and
then call discordrich.respond()
with the user's answer.
The user
table has the same shape as the one provided by handlers.ready()
.
Respond to a join request issued by the user identified by user_id
. answer
must be one of:
discordrich.REPLY_NO
discordrich.REPLY_YES
discordrich.REPLY_IGNORE
Change the handlers
callbacks with different ones.
Register the game's application protocol manually (auto_register
does this
automatically for you).
Register the game's application protocol manually to launch the game through
Steam. (auto_register
does this automatically for you).