Что делает discord rpc
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
danger For now, RPC is in a private beta. We are not currently accepting any new developers into the program at this time.
All Discord clients have an RPC server running on localhost that allows control over local Discord clients.
For connections to the RPC server, a list of approved testers is used to restrict access while you're still developing. You can invite up to 50 people.
For applications/games not approved, we limit you to creating 10 guilds and 10 channels. This limit is raised to virtually unlimited after approval.
Field | Type | Description | Present |
---|---|---|---|
cmd | enum | payload command | Always |
nonce | string | unique string used once for replies from the server | In responses to commands (not subscribed events) |
evt | enum | subscription event | In subscribed events, errors, and (un)subscribing events |
data | object | event data | In responses from the server |
args | object | command arguments | In commands sent to the server |
The local RPC server runs on localhost ( 127.0.0.1 ) and is set up to process WebSocket connections and proxy API requests.
For WebSocket connections, the connection is always ws://127.0.0.1:PORT/?v=VERSION&client_id=CLIENT_ID&encoding=ENCODING :
- CLIENT_ID is the client ID of the application accessing the RPC Server.
- VERSION is the version of the RPC Server.
- PORT is the port of the RPC Server.
- ENCODING is the type of encoding for this connection to use. json and etf are supported.
To begin, you'll need to create an app. Head to your apps and click the big plus button. When you create an app on our Developers site, you must specify an "RPC Origin" and "Redirect URI" from which to permit connections and authorizations. The origin you send when connecting and the redirect uri you send when exchanging an authorization code for an access token must match one of the ones entered on the Developers site.
When establishing a WebSocket connection, we verify the Origin header on connection to prevent client ID spoofing. You will be instantly disconnected if the Origin does not match.
RPC Server Ports
The port range for Discord's local RPC server is [6463, 6472]. Since the RPC server runs locally, there's a chance it might not be able to obtain its preferred port when it tries to bind to one. For this reason, the local RPC server will pick one port out of a range of these 10 ports, trying sequentially until it can bind to one. When implementing your client, you should perform the same sequential checking to find the correct port to connect to.
In order to call any commands over RPC, you must be authenticated or you will receive a code 4006 error response. Thankfully, we've removed the oppressive nature of a couple commands that will let you AUTHORIZE and AUTHENTICATE new users. First, call AUTHORIZE:
RPC Authorize Example
RPC Authenticate Example
You can now call RPC commands on behalf of the authorized user!
Commands and Events
Commands are requests made to the RPC socket by a client.
Name | Description |
---|---|
DISPATCH | event dispatch |
AUTHORIZE | used to authorize a new client with your app |
AUTHENTICATE | used to authenticate an existing client with your app |
GET_GUILD | used to retrieve guild information from the client |
GET_GUILDS | used to retrieve a list of guilds from the client |
GET_CHANNEL | used to retrieve channel information from the client |
GET_CHANNELS | used to retrieve a list of channels for a guild from the client |
SUBSCRIBE | used to subscribe to an RPC event |
UNSUBSCRIBE | used to unsubscribe from an RPC event |
SET_USER_VOICE_SETTINGS | used to change voice settings of users in voice channels |
SELECT_VOICE_CHANNEL | used to join or leave a voice channel, group dm, or dm |
GET_SELECTED_VOICE_CHANNEL | used to get the current voice channel the client is in |
SELECT_TEXT_CHANNEL | used to join or leave a text channel, group dm, or dm |
GET_VOICE_SETTINGS | used to retrieve the client's voice settings |
SET_VOICE_SETTINGS | used to set the client's voice settings |
SET_CERTIFIED_DEVICES | used to send info about certified hardware devices |
SET_ACTIVITY | used to update a user's Rich Presence |
SEND_ACTIVITY_JOIN_INVITE | used to consent to a Rich Presence Ask to Join request |
CLOSE_ACTIVITY_REQUEST | used to reject a Rich Presence Ask to Join request |
Events are payloads sent over the socket to a client that correspond to events in Discord.
Name | Description |
---|---|
READY | non-subscription event sent immediately after connecting, contains server information |
ERROR | non-subscription event sent when there is an error, including command responses |
GUILD_STATUS | sent when a subscribed server's state changes |
GUILD_CREATE | sent when a guild is created/joined on the client |
CHANNEL_CREATE | sent when a channel is created/joined on the client |
VOICE_CHANNEL_SELECT | sent when the client joins a voice channel |
VOICE_STATE_CREATE | sent when a user joins a subscribed voice channel |
VOICE_STATE_UPDATE | sent when a user's voice state changes in a subscribed voice channel (mute, volume, etc.) |
VOICE_STATE_DELETE | sent when a user parts a subscribed voice channel |
VOICE_SETTINGS_UPDATE | sent when the client's voice settings update |
VOICE_CONNECTION_STATUS | sent when the client's voice connection status changes |
SPEAKING_START | sent when a user in a subscribed voice channel speaks |
SPEAKING_STOP | sent when a user in a subscribed voice channel stops speaking |
MESSAGE_CREATE | sent when a message is created in a subscribed text channel |
MESSAGE_UPDATE | sent when a message is updated in a subscribed text channel |
MESSAGE_DELETE | sent when a message is deleted in a subscribed text channel |
NOTIFICATION_CREATE | sent when the client receives a notification (mention or new message in eligible channels) |
ACTIVITY_JOIN | sent when the user clicks a Rich Presence join invite in chat to join a game |
ACTIVITY_SPECTATE | sent when the user clicks a Rich Presence spectate invite in chat to spectate a game |
ACTIVITY_JOIN_REQUEST | sent when the user receives a Rich Presence Ask to Join request |
Used to authenticate a new client with your app. By default this pops up a modal in-app that asks the user to authorize access to your app.
We currently do not allow access to RPC for unapproved apps without being on the game's list of testers. We grant 50 testing spots, which should be ample for development. After approval, this restriction is removed and your app will be accessible to anyone.
This library has been deprecated in favor of Discord's GameSDK. Learn more here
This is a library for interfacing your game with a locally running Discord desktop client. It's known to work on Windows, macOS, and Linux. You can use the lib directly if you like, or use it as a guide to writing your own if it doesn't suit your game as is. PRs/feedback welcome if you have an improvement everyone might want, or can describe how this doesn't meet your needs.
Included here are some quick demos that implement the very minimal subset to show current status, and have callbacks for where a more complete game would do more things (joining, spectating, etc).
The most up to date documentation for Rich Presence can always be found on our developer site! If you're interested in rolling your own native implementation of Rich Presence via IPC sockets instead of using our SDK—hey, you've got free time, right?—check out the "Hard Mode" documentation.
Zeroith, you should be set up to build things because you are a game developer, right?
First, head on over to the Discord developers site and make yourself an app. Keep track of Client ID -- you'll need it here to pass to the init function.
Unreal Engine 4 Setup
To use the Rich Presense plugin with Unreal Engine Projects:
- Download the latest release for each operating system you are targeting and the zipped source code
- In the source code zip, copy the UE plugin— examples/unrealstatus/Plugins/discordrpc —to your project's plugin directory
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create an Include folder and copy discord_rpc.h and discord_register.h to it from the zip
- Follow the steps below for each OS
- Build your UE4 project
- Launch the editor, and enable the Discord plugin.
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create a Win64 folder
- Copy lib/discord-rpc.lib and bin/discord-rpc.dll from [RELEASE_ZIP]/win64-dynamic to the Win64 folder
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create a Mac folder
- Copy libdiscord-rpc.dylib from [RELEASE_ZIP]/osx-dynamic/lib to the Mac folder
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create a Linux folder
- Inside, create another folder x86_64-unknown-linux-gnu
- Copy libdiscord-rpc.so from [RELEASE_ZIP]/linux-dynamic/lib to Linux/x86_64-unknown-linux-gnu
If you're a Unity developer looking to integrate Rich Presence into your game, follow this simple guide to get started towards success:
- Download the DLLs for any platform that you need from our releases
- In your Unity project, create a Plugins folder inside your Assets folder if you don't already have one
- Copy the file DiscordRpc.cs from here into your Assets folder. This is basically your header file for the SDK
We've got our Plugins folder ready, so let's get platform-specific!
- Create x86 and x86_64 folders inside Assets/Plugins/
- Copy discord-rpc-win/win64-dynamic/bin/discord-rpc.dll to Assets/Plugins/x86_64/
- Copy discord-rpc-win/win32-dynamic/bin/discord-rpc.dll to Assets/Plugins/x86/
- Click on both DLLs and make sure they are targetting the correct architectures in the Unity editor properties pane
- Done!
- Copy discord-rpc-osx/osx-dynamic/lib/libdiscord-rpc.dylib to Assets/Plugins/
- Rename libdiscord-rpc.dylib to discord-rpc.bundle
- Done!
- Copy discord-rpc-linux/linux-dynamic-lib/libdiscord-rpc.so to Assets/Plugins/
- Done!
You're ready to roll! For code examples on how to interact with the SDK using the DiscordRpc.cs header file, check out our example
Download a release package for your platform(s) -- they have subdirs with various prebuilt options, select the one you need add /include to your compile includes, /lib to your linker paths, and link with discord-rpc . For the dynamically linked builds, you'll need to ship the associated file along with your game.
First-eth, you'll want CMake . There's a few different ways to install it on your system, and you should refer to their website. Many package managers provide ways of installing CMake as well.
To make sure it's installed correctly, type cmake --version into your flavor of terminal/cmd. If you get a response with a version number, you're good to go!
There's a CMake file that should be able to generate the lib for you; Sometimes I use it like this:
There is a wrapper build script build.py that runs cmake with a few different options.
Usually, I run build.py to get things started, then use the generated project files as I work on things. It does depend on click library, so do a quick pip install click to make sure you have it if you want to run build.py .
There are some CMake options you might care about:
flag | default | does |
---|---|---|
ENABLE_IO_THREAD | ON | When enabled, we start up a thread to do io processing, if disabled you should call Discord_UpdateConnection yourself. |
USE_STATIC_CRT | OFF | (Windows) Enable to statically link the CRT, avoiding requiring users install the redistributable package. (The prebuilt binaries enable this option) |
BUILD_SHARED_LIBS | OFF | Build library as a DLL |
WARNINGS_AS_ERRORS | OFF | When enabled, compiles with -Werror (on *nix platforms). |
Why do we have three of these? Three times the fun!
CI | badge |
---|---|
TravisCI | |
AppVeyor | |
Buildkite (internal) |
This is a text adventure "game" that inits/deinits the connection to Discord, and sends a presence update on each command.
This is a sample Unity project that wraps a DLL version of the library, and sends presence updates when you click on a button. Run python build.py unity in the root directory to build the correct library files and place them in their respective folders.
This is a sample Unreal project that wraps the DLL version of the library with an Unreal plugin, exposes a blueprint class for interacting with it, and uses that to make a very simple UI. Run python build.py unreal in the root directory to build the correct library files and place them in their respective folders.
Wrappers and Implementations
Below is a table of unofficial, community-developed wrappers for and implementations of Rich Presence in various languages. If you would like to have yours added, please make a pull request adding your repository to the table. The repository should include:
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
This library has been deprecated in favor of Discord's GameSDK. Learn more here
This is a library for interfacing your game with a locally running Discord desktop client. It's known to work on Windows, macOS, and Linux. You can use the lib directly if you like, or use it as a guide to writing your own if it doesn't suit your game as is. PRs/feedback welcome if you have an improvement everyone might want, or can describe how this doesn't meet your needs.
Included here are some quick demos that implement the very minimal subset to show current status, and have callbacks for where a more complete game would do more things (joining, spectating, etc).
The most up to date documentation for Rich Presence can always be found on our developer site! If you're interested in rolling your own native implementation of Rich Presence via IPC sockets instead of using our SDK—hey, you've got free time, right?—check out the "Hard Mode" documentation.
Zeroith, you should be set up to build things because you are a game developer, right?
First, head on over to the Discord developers site and make yourself an app. Keep track of Client ID -- you'll need it here to pass to the init function.
Unreal Engine 4 Setup
To use the Rich Presense plugin with Unreal Engine Projects:
- Download the latest release for each operating system you are targeting and the zipped source code
- In the source code zip, copy the UE plugin— examples/unrealstatus/Plugins/discordrpc —to your project's plugin directory
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create an Include folder and copy discord_rpc.h and discord_register.h to it from the zip
- Follow the steps below for each OS
- Build your UE4 project
- Launch the editor, and enable the Discord plugin.
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create a Win64 folder
- Copy lib/discord-rpc.lib and bin/discord-rpc.dll from [RELEASE_ZIP]/win64-dynamic to the Win64 folder
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create a Mac folder
- Copy libdiscord-rpc.dylib from [RELEASE_ZIP]/osx-dynamic/lib to the Mac folder
- At [YOUR_UE_PROJECT]/Plugins/discordrpc/source/ThirdParty/DiscordRpcLibrary/ , create a Linux folder
- Inside, create another folder x86_64-unknown-linux-gnu
- Copy libdiscord-rpc.so from [RELEASE_ZIP]/linux-dynamic/lib to Linux/x86_64-unknown-linux-gnu
If you're a Unity developer looking to integrate Rich Presence into your game, follow this simple guide to get started towards success:
- Download the DLLs for any platform that you need from our releases
- In your Unity project, create a Plugins folder inside your Assets folder if you don't already have one
- Copy the file DiscordRpc.cs from here into your Assets folder. This is basically your header file for the SDK
We've got our Plugins folder ready, so let's get platform-specific!
- Create x86 and x86_64 folders inside Assets/Plugins/
- Copy discord-rpc-win/win64-dynamic/bin/discord-rpc.dll to Assets/Plugins/x86_64/
- Copy discord-rpc-win/win32-dynamic/bin/discord-rpc.dll to Assets/Plugins/x86/
- Click on both DLLs and make sure they are targetting the correct architectures in the Unity editor properties pane
- Done!
- Copy discord-rpc-osx/osx-dynamic/lib/libdiscord-rpc.dylib to Assets/Plugins/
- Rename libdiscord-rpc.dylib to discord-rpc.bundle
- Done!
- Copy discord-rpc-linux/linux-dynamic-lib/libdiscord-rpc.so to Assets/Plugins/
- Done!
You're ready to roll! For code examples on how to interact with the SDK using the DiscordRpc.cs header file, check out our example
Download a release package for your platform(s) -- they have subdirs with various prebuilt options, select the one you need add /include to your compile includes, /lib to your linker paths, and link with discord-rpc . For the dynamically linked builds, you'll need to ship the associated file along with your game.
First-eth, you'll want CMake . There's a few different ways to install it on your system, and you should refer to their website. Many package managers provide ways of installing CMake as well.
To make sure it's installed correctly, type cmake --version into your flavor of terminal/cmd. If you get a response with a version number, you're good to go!
There's a CMake file that should be able to generate the lib for you; Sometimes I use it like this:
There is a wrapper build script build.py that runs cmake with a few different options.
Usually, I run build.py to get things started, then use the generated project files as I work on things. It does depend on click library, so do a quick pip install click to make sure you have it if you want to run build.py .
There are some CMake options you might care about:
flag | default | does |
---|---|---|
ENABLE_IO_THREAD | ON | When enabled, we start up a thread to do io processing, if disabled you should call Discord_UpdateConnection yourself. |
USE_STATIC_CRT | OFF | (Windows) Enable to statically link the CRT, avoiding requiring users install the redistributable package. (The prebuilt binaries enable this option) |
BUILD_SHARED_LIBS | OFF | Build library as a DLL |
WARNINGS_AS_ERRORS | OFF | When enabled, compiles with -Werror (on *nix platforms). |
Why do we have three of these? Three times the fun!
CI | badge |
---|---|
TravisCI | |
AppVeyor | |
Buildkite (internal) |
This is a text adventure "game" that inits/deinits the connection to Discord, and sends a presence update on each command.
This is a sample Unity project that wraps a DLL version of the library, and sends presence updates when you click on a button. Run python build.py unity in the root directory to build the correct library files and place them in their respective folders.
This is a sample Unreal project that wraps the DLL version of the library with an Unreal plugin, exposes a blueprint class for interacting with it, and uses that to make a very simple UI. Run python build.py unreal in the root directory to build the correct library files and place them in their respective folders.
Wrappers and Implementations
Below is a table of unofficial, community-developed wrappers for and implementations of Rich Presence in various languages. If you would like to have yours added, please make a pull request adding your repository to the table. The repository should include:
Simple Discord RPC показывает ваш статус в discord. Умеет показывать что именно вы делаете в игре, на каком сервере играете, в каком биоме или на каких координатах. В отличии от Simple Discord Rich Presence не требует настройки и сложных махинаций для работы. Он выполняет все свои функции сразу после установки, но делает это на английском. Сейчас я расскажу как его перевести и настроить по вкусу:
Все настройки мода находятся в файле "simple-rpc.json", который расположен в папке .minecraft/config.
В нём всё разделено на блоки: main_menu, server_list и т.д. Для каждого блока подписи можно настроить отдельно, или вовсе отключить конкретный блок (под названием блока в строке "enabled" меняем "true" на "false").
На скриншоте выделен блок подписей когда игрок в одиночной игре
теперь по пунктам:
Остальные пункты я не затрагивал, и не знаю зачем именно они надо.
Не спешите в блокнот, ведь если вы просто измените всё в блокноте, то вместо букв вы увидите это:
Для того чтобы мод понял что вы ввели русские буквы, надо изменить кодировку конфиг-файла на UTF-8. Я знаю лишь один метод менять кодировку - программа Notepad++. Но в моём конфиг-файле кодировка уже заменена, так что сможете редактировать его блокнотом. А вообще в Notepad++ это делается так:
Не забудьте сохранить файл чтобы значок возле имени стал синим:
Также в файле можно заметить %такое%. Это сменные, которые заменяются словами в соответствии с вашей игрой:
%player% - Ваш ник в игре
%mcver% - Версия вашей игры
%mods% - Количество установленных модов
%world% - Измерение, в котором вы находитесь (из коробки поддерживает только три ванильные измерения, однако можно добавлять и свои из модов). Внизу есть большой блок "worlds", там вся информация об измерениях.
%difficulty% - сложность в игре
%position% - координаты игрока
%biome% - показывает текущий биом (например Taiga, Plains, Desert и т.д.)
%servername% - название сервера, на котором вы играете
%ip% - айпи адрес сервера, на котором вы играете
%players% - количество игроков на сервере (не включая вас)
Думаю, на этом гайд можно закончить. Если вам лень это делать и вы просто хотите готовый перевод, то внизу скачайте simple-rpc.json и поместите его в .minecraft/config (с заменой если мод уже был загружен).
To do: This implementation is fairly basic, so any edits or additions are greatly appreciated!
Implementing Discord RPC into the Source engine is simple, and it makes your mod stand out more, as your in-game "presence" can be seen through Discord.
Contents
The Installation
First off you'll need to download the latest version Discord RPC. You can do so by going to Discord's GitHub repository here. And download the latest discord-rpc-win.zip file, as of writing we'll be using v3.3.0. Once downloaded, open the archive and go to win32-dynamic/lib/ and extract discord-rpc.lib to your mod's /src/lib/public/ once that's done we'll do the same for the include files, in your archive take a step back and go into the include folder, now extract discord_rpc.h and discord_register.h to /src/public/. Now for the final step, once again in your archive take a step back and go into the bin folder, now extract discord-rpc.dll to your mod's /bin folder ex. /steamapps/sourcemods/YourMod/bin/.
Conclusion
The installation and setup are both complete! Try launching your mod and check your Discord status, now load up a map and check again!
This implementation works on Source SDK 2013 (SP/MP), as well as Source SDK 2007 (thanks to the IOSoccer team for testing!).
What is Discord RPC?
Discord RPC is a library for interfacing your game with a locally running Discord desktop client. It's known to work on Windows, macOS, and Linux. You can use the lib directly if you like, or use it as a guide to writing your own if it doesn't suit your game as is.
Below is an example using this article as a base, with obvious modifications:
The Setup
Now that the installation is done, it's time to set up our system. There's not a whole lot to do here, but this is a necessary step you'll have to take to make the implementation work.
To start off, go into /src/vpc_scripts/ and open source_dll_win32_base.vpc with your favorite text editor (I personally use Notepad++). Once you've opened the file, scroll all the way down to $Folder "Link Libraries" and under $Implib "$LIBPUBLIC\vstdlib" add $Lib "$LIBPUBLIC\discord-rpc" . After you've modified the VPC scripts, make sure to rerun createallprojects.bat and/or creategameprojects.bat before continuing, otherwise you might experience errors while building.
where the numbers after cl_discord_appid is your application's RPC AppID, to set up a RPC client go here, once your application is set up the number you'll want to place after cl_discord_appid is the "Client ID" seen in "General Information".
When that's done add the following above CHLClient::CHLClient()
Now scroll down to CHLClient::Init( . ) and add the following above return true; at the bottom of the function.
"ModImageHere" is an image key, remember that Discord developer page you were on earlier, where you set up your application? Go back there and to your application page, now go down to "Rich Presence" and click on "Art Assets" and click "Add Image(s)". Add an image you want for your mod and whatever you name that image is the name you replace "ModImageHere" with.
Now go further down to CHLClient::LevelInitPreEntity( . ) and above the comment for g_RagdollLVManager.SetLowViolence( pMapName ); add
Now we'll add the last piece of code into CHLClient::LevelShutdown( void ) . Below
Читайте также: