This package was created to make it easier for Discord users to create a custom rich presence on their profile. Yes, that's it.
- Go to https://discord.com/developers/applications
- Click "New Application" if you don't have application
- Insert the name of your application
- Copy
APPLICATION ID
-
Installing stable version
The safetest way to install stable version is using PIP command line. Run this command in cmd/terminal :
pip install discord-rpc
-
Installing unstable/development version
There are 2 methods for installing the development version, namely from TestPyPI or directly from GitHub.
- From TestPyPI
pip install -i https://test.pypi.org/simple/ discord-rpc
- Directly from Github
pip install git+https://github.com/Senophyx/Discord-RPC.git
- From TestPyPI
Step-by-step making simple rich presence using Discord-RPC.
-
Make sure Discord-RPC is installed.
-
Import Discord-RPC
import discordrpc
-
Creating
rpc
variable fromdiscordrpc.RPC
. And insert your app ID (Tutorial).rpc = discordrpc.RPC(app_id=1234) #Change app_id to your app id
-
Customizing activity using
rpc.set_activity()
.rpc.set_activity( state="A super simple rpc", details="simple RPC" )
-
Creating loop for
rpc
so that it can keep running. (Only required if you only run Discord RPC on this file or current instance)rpc.run()
-
Done! Run your file.
Examples can be seen in the repository (Discord-RPC/examples
) or here.
-
discordrpc.RPC()
Parameters :- app_id (
int
) : Application ID (Tutorial) - debug (
bool
) : Print more informative output. Default = False - output (
bool
) : Print output or not. Default = True
- app_id (
-
method
RPC.set_activity()
Set activity to be displayed on the user's Discord profile.Parameters :
- state (
str
) - details (
str
) - act_type (
int
) : Activity Types (Activity Type1
and4
is currently disabled, see #28). - ts_start (
int
) : Timestamp start. - ts_end (
int
) : Timestamp end. - large_image (
str
) : The name of the image that has been uploaded to the Discord Developer Portal. - large_text (
str
) : Text when user hover tolarge_image
. - small_image (
str
) : The name of the image that has been uploaded to the Discord Developer Portal. - small_text (
str
) : Text when user hover tosmall_image
. - party_id (
int
) : id of the user’s party. - party_size (
list
) : party size in list with format[current_size, max_size]
or[1, 10]
. - join_secret (
str
) : Secret for chat invitations and ask to join button. - spectate_secret (
str
) : Secret for spectate button. - match_secret (
str
) : Secret for for spectate and join button - buttons (
list
) : list of dicts for buttons on user's profile. You can usediscordrpc.button.Button
for more easier.
Return : nothing.
- state (
-
method
RPC.disconnect()
Disconnecting and closing RPC socket.Return : nothing.
-
method
RPC.run()
Keeping rpc alive. Not required if another tasks is running on the same file.Parameters :
- update_every (
int
) :time.sleep
every inputed second.
Exceptions :
KeyboardInterrupt
will callRPC.disconnect
.
Return : nothing.
- update_every (
-
variable
self.is_connected
Check whether the RPC successfully handshaked and connected to the Discord socket.Return :
True
orFalse
-
variable
self.is_running
Checks whether the RPC successfully updatedRPC.set_activity
or not.Return :
True
orFalse
-
function
Button()
Simplified button payload inRPC.set_activity
Parameters :
- button_one_label (
str
) : Label for button one. - button_one_url (
str
) : Url for button one. - button_two_label (
str
) : Label for button two. - button_two_url (
str
) : Url for button two.
Return : List of button dict.
- button_one_label (
-
variable
discordrpc.utils.timestamp()
Return current time in epoch timestamp (int
). -
function
discordrpc.utils.date_to_timestamp()
Date to timestamp converter.Parameters :
- date (
str
) : a date and time in string with format%d/%m/%Y-%H:%M:%S
orday/month/year-hour:minute:second
. Example :
date_to_timestamp('14/06/2025-00:00:00')
- date (
-
RPCException
Raising errors that don't know what the specific error is and how to fix it. -
Error
Raising unspecific errors. The error and how to fix it are in the message. -
DiscordNotOpened
Discord client not running or not found.How-to-Fix : just open discord :)
-
ActivityError
Error in theset_activity
method. Usually due to entering the payload incorrectly.How-to-Fix : Make sure
set_activity
are set correctly. -
InvalidURL
The URL in theButton
function is incorrect because it does not start withhttp://
orhttps://
.How-to-Fix : Make sure the URL starts with
http://
orhttps://
-
InvalidID
Application ID is incorrect or not found.How-to-Fix : make sure you input the ID correctly from https://discord.com/developers/applications. (Tutorial how to get application id)
-
ButtonError
There is an error in theButton
function, usually because the required parameters are not set/input.How-to-Fix : Check if
Button
function are set correctly
Discord-RPC project is under MIT License
Copyright (c) 2021-2024 Senophyx and EterNomm.