-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Here I'm going to explain a set of np_
functions provided by NekoPresence. And also asynchronous events.
I highly recommend you read this page first https://discord.com/developers/docs/rich-presence/how-to#so-how-does-it-work and then return here, in order to understand what are image keys, user ids, etc. (Callbacks are Social Async events in NekoPresence)
np_initdiscord(client_id, autoRegister, steam_id)
(String) client_id - Your Discord app's client/app id
(Bool) autoRegister - whether or not to register an application protocol for your game on the player's computer—necessary to launch games from Discord
(String) steam_id - Your game's Steam ID, pass "0" if none, you can use np_steam_app_id macro to get your app's steam id as a string.
Initializes connection with your Discord client. Please call it before calling any other function.
Returns true
if initialization was successful, and false
if an error occurred.
np_update()
Updates extension's state, must be called every Step to trigger asynchronous events.
Returns true
if operation was successful, and false
if an error occurred.
np_setpresence(state, details, large_image_key, small_image_key)
(String) state - the user's current party status
(String) details - what the player is currently doing
(String) large_image_key - Large Image Key as a string (as in App Assets menu in Discord Devs dashboard)
(String) small_image_key - Small Image Key as a string (as in App Assets menu in Discord Devs dashboard)
Updates player's Rich Presence. To set more information call np_setpresence_more
BEFORE this function!
Returns true
if operation was successful, and false
if an error occurred.
np_setpresence_more(small_image_text, large_image_text, instance)
(String) small_image_text - tooltip for the small_image_key
(String) large_image_text - tooltip for the large_image_key
(Boolean) instance - Currently unused, as this extension doesn't support lobbies yet. (just pass false)
Sets additional info for Rich Presence, must be called BEFORE np_setpresence in order to do anything!
Returns true
if operation was successful, and false
if an error occurred.
np_setpresence_secrets(matchSecret, spectateSecret, joinSecret)
(String) matchSecret - unique hashed string for a player's match.
(String) spectateSecret - unique hashed string for Spectate button.
(String) joinSecret - unique hashed string for chat invitations and Ask to Join.
You can use this function to set secret values for your Rich Presence payload, must be called BEFORE np_setpresence in order to do anything!
Returns true
if operation was successful, and false
if an error occurred.
np_setpresence_clearsecrets()
Clears all secret values that were set via np_setpresence_secrets
.
In some cases you only want to clear secrets (to set new ones for example), you can use this function to clear all secrets that were set by this extension.
Returns true
if operation was successful, and false
if an error occurred.
np_setpresence_partyparams(partySize, partyMax, partyId, partyPrivacy)
(Integer) partySize - current size of the player's party, lobby, or group.
(Integer) partyMax - maximum size of the player's party, lobby, or group.
(String) partyId - id of the player's party, lobby, or group.
(DISCORD_PARTY_PRIVACY_) partyPrivacy - party privacy level, can be DISCORD_PARTY_PRIVACY_PRIVATE or DISCORD_PARTY_PRIVACY_PUBLIC.
You can use this function to set various party options (for setting secret values please refer to np_setpresence_secrets
)
Must be called BEFORE np_setpresence in order to do anything!
Returns true
if operation was successful, and false
if an error occurred.
np_clearpresence()
Clears user's Rich Presence, all secrets, all party options, all timestamps, and resets instance
flag to 0.
Returns true
if operation was successful, and false
if an error occurred.
np_setpresence_timestamps(startTimestamp, endTimestamp, is_unix)
(Integer) startTimestamp - epoch* seconds for game start - including will show time as "elapsed".
(Integer) endTimestamp - epoch* seconds for game end - including will show time as "remaining".
(Boolean) is_unix - if your timestamp is a UNIX Epoch timestamp or it's a GM DateTime timestamp.
- Epoch as in UNIX Timestamp, it IS NOT GameMaker's DateTime timestamp, please set
is_unix
tofalse
if you're usingdate_*
functions to get the current date.
If you set endTimestamp
to zero, it'll show startTimestamp
as Elapsed and Discord will count up.
Sets "Elapsed" and "Remaining" timestamps for Rich Presence payload.
Must be called BEFORE np_setpresence in order to do anything!
Returns true
if operation was successful, and false
if an error occurred.
np_respond(user_id, reply)
(String) user_id - user's id.
(Discord Reply) reply - can be DISCORD_REPLY_NO, DISCORD_REPLY_YES or DISCORD_REPLY_IGNORE
When you get a DiscordJoinRequest event, you must reply to it by using this function.
See DiscordJoinEvent entry below for more information.
(you can get user_id from the DiscordJoinRequest ds map)
Returns true
if operation was successful, and false
if an error occurred.
np_registergame(client_id, command)
(String) client_id - Your Discord Client/App ID.
(String) command - Command that Discord should execute to launch your game.
Tells Discord how it should launch your game (if it wants to).
For example when a player clicked Spectate, Discord will launch your game and fire off a DiscordSpectateGame
async event, same with DiscordJoinGame
event.
Make sure you format the command properly, otherwise it may not work.
Returns true
if operation was successful, and false
if an error occurred.
np_registergame_steam(client_id, steam_id)
(String) client_id - Your Discord Client/App ID.
(String) steam_id - Your game's Steam ID as a string, you can use np_steam_app_id macro to get your app's steam id as a string.
Same as np_registergame
but it does steam://run/steam_id_here
instead and not just blindly execute a command.
Returns true
if operation was successful, and false
if an error occurred.
np_get_avatar_url(user_id, avatar_hash)
(String) user_id - User ID (you can get it from DiscordReady or DiscordJoinRequest async event).
(String) avatar_hash - User's avatar hash (same).
Returns a URL to an avatar .png if operation was successful, and an empty string if one of the values are empty strings, or a weird error occurred.
np_setpresence_buttons(btnId, btnName, btnUrl)
(Integer) - btnId - can be either 0 or 1.
(String) - btnName - Name of the button, cannot be an empty string.
(String) - btnUrl - URL to where the button will point to, cannot be an empty string.
Sets the label and the url of a button, there can only be up to 2 buttons created.
Please always set button names from 0 to 1.
Do not leave the button 0 empty if you have a button 1 set.
Returns true
if operation was successful, and false
if an error occurred.
You may notice that there are some functions prefixed with __
.
They are called automatically by GM, please please please NEVER call them manually, they are for GM.
They're basically the results of Discord-RPC callbacks.
Each event has an event_type
key, this is the way how you check for a specific event.
And that's how I'm going to explain these.
(String) user_id - User's Discord User ID.
(String) discriminator - User's username discriminator.
(String) username - User's username (without discriminator).
(String) avatar - User's avatar id.
Happens when Discord-senpai noticed your game-kyun. You get the user-chan's info so that's nice. owo
(String) error_message - Error message.
(Integer) error_code - Error code.
Happens when some sort of an error occurred, let's hope you'll never get it.
(String) user_id - User's Discord User ID. (can be used in np_reply)
(String) discriminator - User's username discriminator.
(String) username - User's username (without discriminator).
(String) avatar - User's avatar id.
Happens when an another player clicked "Ask to Join" in your Rich Presence status.
You must reply to this event (in... 30 seconds I guess?) by using the np_reply
function (see above).
(String) join_secret - Join secret value you set via np_setpresence_secrets
Happens when a player joins your game, they get this event with a join_secret
.
(String) spectate_secret - Spectate secret value you set via np_setpresence_secrets
When a user clicks "Spectate" on your profile, their game will open via the command you've set via np_registergame
or np_registergame_steam
and then they will get this event containing spectate_secret
.
(Integer) error_code - error code.
(String) error_message - error message.
Happens when you get kicked out of Discord for some reason. (Perhaps a bad internet connection?)