Skip to content

Latest commit

 

History

History
195 lines (139 loc) · 6.41 KB

DOCS.md

File metadata and controls

195 lines (139 loc) · 6.41 KB

Discord RPC Documentation

This package was created to make it easier for Discord users to create a custom rich presence on their profile. Yes, that's it.

Dicord-RPC preview

Getting application ID

  1. Go to https://discord.com/developers/applications
  2. Click "New Application" if you don't have application
  3. Insert the name of your application
  4. Copy APPLICATION ID

Installing Discord-RPC

  • 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.

    1. From TestPyPI
    pip install -i https://test.pypi.org/simple/ discord-rpc
    
    1. Directly from Github
    pip install git+https://github.com/Senophyx/Discord-RPC.git
    

Quickstart

Step-by-step making simple rich presence using Discord-RPC.

  1. Make sure Discord-RPC is installed.

  2. Import Discord-RPC

    import discordrpc
  3. Creating rpc variable from discordrpc.RPC. And insert your app ID (Tutorial).

    rpc = discordrpc.RPC(app_id=1234) #Change app_id to your app id
  4. Customizing activity using rpc.set_activity().

    rpc.set_activity(
      state="A super simple rpc",
      details="simple RPC"
    )
  5. 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()
  6. Done! Run your file.

Examples

Examples can be seen in the repository (Discord-RPC/examples) or here.

class discordrpc.RPC()

  • 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
  • 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 Type 1 and 4 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 to large_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 to small_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 use discordrpc.button.Button for more easier.

    Return : nothing.

  • 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 call RPC.disconnect.

    Return : nothing.

  • variable self.is_connected
    Check whether the RPC successfully handshaked and connected to the Discord socket.

    Return : True or False

  • variable self.is_running
    Checks whether the RPC successfully updated RPC.set_activity or not.

    Return : True or False

class discordrpc.Button()

  • function Button()
    Simplified button payload in RPC.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.

class discordrpc.utils

  • 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 or day/month/year-hour:minute:second. Example :

      date_to_timestamp('14/06/2025-00:00:00')

Exceptions & Errors

  • 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 the set_activity method. Usually due to entering the payload incorrectly.

    How-to-Fix : Make sure set_activity are set correctly.

  • InvalidURL
    The URL in the Button function is incorrect because it does not start with http:// or https://.

    How-to-Fix : Make sure the URL starts with http:// or https://

  • 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 the Button function, usually because the required parameters are not set/input.

    How-to-Fix : Check if Button function are set correctly

Links

Licence & Copyright

Discord-RPC project is under MIT License
Copyright (c) 2021-2024 Senophyx and EterNomm.