Home

Awesome

lua-discordRPC

LuaJIT bindings for the Discord Rich Presence library (v3.3.0).

Usage

To use this library, download the binaries of discord-rpc (or build them yourself) and make sure the dynamic library is in some location it can be loaded from (e.g. on Windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx, usually just next to the executable).

If you downloaded a release from the discord-rpc github, the file you are looking for will be in discord-rpc/winX-dynamic/bin/discord-rpc.dll (choose X according to whether your executable is 32 or 64 bit)

Then just do local discordRPC = require "discordRPC" wherever you need it.

If you are using löve, just put the appropriate .dll next to your löve executable

An example of the usage of the library using löve can be found in main.lua.

Documentation

How and when to use the functions that are part of the Discord RPC API is identical to the C API, therefore you should first make yourself familiar with the API documentation on Discord's website:

https://discordapp.com/developers/docs/rich-presence/how-to

All other differences and the function signatures are as follows:

discordRPC.initialize(applicationId, autoRegister, optionalSteamId) (Discord_Initialize)

You do not have to pass handlers to this function, instead you may define functions in the module table of discordRPC:

Notes about callbacks: Just-In-Time compilation is disabled for callbacks (for reasons, see the comment in the implementation of discordRPC.runCallbacks), so try to avoid doing performance critical tasks in them.

discordRPC.ready(userId, username, discriminator, avatar)

userId, username, discriminator and avatar are all strings

discordRPC.errored(errorCode, message)

discordRPC.disconnected(errorCode, message)

discordRPC.joinGame(joinSecret)

joinSecret is a string

discordRPC.spectateGame(spectateSecret)

spectateSecret is a string

discordRPC.joinRequest(userId, username, discriminator, avatar)

userId, username, discriminator and avatar are all strings

discordRPC.shutdown() (Discord_Shutdown)

discordRPC.runCallbacks() (Discord_RunCallbacks)

discordRPC.updatePresence(presence) (Discord_UpdatePresence)

presence must be a table with the following keys (all optional):

discordRPC.clearPresence() (Discord_ClearPresence)

discordRPC.respond(userId, reply) (Discord_Respond)