Client() — pypresence 4.6.0 documentation

# Client()

class Client(client_id, pipe=0, loop=None, handler=None)

  Creates the RPC client ready for usage.

  Parameters:

    - client_id (str) – OAuth2 App ID (found at https://discord.com/developers/applications/me)

    - pipe (int) – Pipe that should be used to connect to the Discord client. Defaults to 0, can be 0-9

    - loop (asyncio.BaseEventLoop) – Your own event loop (if you have one) that PyPresence should use. One will be created if not supplied. Information at https://docs.python.org/3/library/asyncio-eventloop.html

    - handler (function) – The exception handler pypresence should send asynchronous errors to. This can be a coroutine or standard function as long as it takes two arguments (exception, future). Exception will be the exception to handle and future will be an instance of asyncio.Future

> start()

>   Initializes the connection - must be done in order to run RPC commands.

>   Return type:

>     pypresence.Response

> close()

>   Closes the connection.

> authorize(client_id, scopes, rpc_token=None, username=None)

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

>   Parameters:

>     - client_id (str) – OAuth2 application id

>     - scopes (list) – a list of OAuth scopes as strings

>     - rpc_token (str) – one-time use RPC token

>     - username (str) – username to create a guest account with if the user does not have Discord

>   Return type:

>     pypresence.Response

>   All the different scopes can be found here

> authenticate(token)

>   Used to authenticate an existing client with your app.

>   Parameters:

>     token (int) – OAuth2 access token

>   Return type:

>     pypresence.Response

> get_guilds()

>   Used to get a list of guilds the client is in.

>   Return type:

>     pypresence.Response

> get_channels()

>   Used to get a guild’s channels the client is in.

>   Return type:

>     pypresence.Response

> channel_id()

>   Used to get a channel the client is in.

>   Parameters:

>     channel_id (str) – id of the channel to get

>   Return type:

>     pypresence.Response

> set_user_voice_settings(user_id, **options)

>   Used to get a channel the client is in.

>   Parameters:

>     - user_id (str) – user id

>     - pan_left (float) – left pan of the user

>     - pan_right (float) – right pan of the user

>     - volume (int) – the volume of user (defaults to 100, min 0, max 200)

>     - mute (bool) – the mute state of the user

>   Return type:

>     pypresence.Response

> select_voice_channel(channel_id)

>   Used to join and leave voice channels, group dms, or dms.

>   Parameters:

>     channel_id (str) – channel id to join (or `None` to leave)

>   Return type:

>     pypresence.Response

> get_selected_voice_channel()

>   Used to get the client’s current voice channel.

>   Return type:

>     pypresence.Response

> select_text_channel(channel_id)

>   Used to join and leave text channels, group dms, or dms.

>   Parameters:

>     channel_id (str) – channel id to join (or `None` to leave)

>   Return type:

>     pypresence.Response

> set_activity(**options)

>   Used to set the activity shown on Discord profiles and status of users. Takes the following as parameters.

>   Parameters:

>     - pid (int) – the process id of your game

>     - state (str) – the user’s current status

>     - details (str) – what the player is currently doing

>     - start (int) – epoch time for game start

>     - end (int) – epoch time for game end

>     - large_image (str) – name of the uploaded image for the large profile artwork

>     - large_text (str) – tooltip for the large image

>     - small_image (str) – name of the uploaded image for the small profile artwork

>     - small_text (str) – tootltip for the small image

>     - party_id (str) – id of the player’s party, lobby, or group

>     - party_size (list) – current size of the player’s party, lobby, or group, and the max in this format: `[1,4]`

>     - join (str) – unique hashed string for chat invitations and ask to join

>     - spectate (str) – unique hashed string for spectate button

>     - match (str) – unique hashed string for spectate and join

>     - buttons (list) – list of dicts for buttons on your profile in the format `[{"label": "My Website", "url": "https://qtqt.cf"}, ...]`, can list up to two buttons

>     - instance (bool) – marks the match as a game session with a specific beginning and end

>   Return type:

>     pypresence.Response

> clear_activity(pid=os.getpid())

>   Clear the activity.

>   Parameters:

>     - pid (int) – the process id of your game

>     - state (str) – the user’s current status

>     - details (str) – what the player is currently doing

>     - start (int) – epoch time for game start

>     - end (int) – epoch time for game end

>     - large_image (str) – name of the uploaded image for the large profile artwork

>     - large_text (str) – tooltip for the large image

>     - small_image (str) – name of the uploaded image for the small profile artwork

>     - small_text (str) – tootltip for the small image

>     - party_id (str) – id of the player’s party, lobby, or group

>     - party_size (list) – current size of the player’s party, lobby, or group, and the max in this format: `[1,4]`

>     - join (str) – unique hashed string for chat invitations and ask to join

>     - spectate (str) – unique hashed string for spectate button

>     - match (str) – unique hashed string for spectate and join

>     - instance (bool) – marks the match as a game session with a specific beginning and end

>   Return type:

>     pypresence.Response

> subscribe(event, args={})

>   Used to subscribe to events.

>   Parameters:

>     - event (str) – event name to subscribe to

>     - args (dict) – any args to go along with the event

>   Return type:

>     pypresence.Response

> unsubscribe(event, args={})

>   Used to unsubscribe from events.

>   Parameters:

>     - event (str) – event name to unsubscribe from

>     - args (dict) – any args to go along with the event

>   Return type:

>     pypresence.Response

> get_voice_settings()

>   Get the user’s voice settings.

>   Return type:

>     pypresence.Response

> set_voice_settings(**options)

>   Set the user’s voice settings.

>   Parameters:

>     - _input (dict) – input settings

>     - output (dict) – output settings

>     - mode (dict) – voice mode settings

>     - automatic_gain_control (bool) – state of automatic gain control

>     - echo_cancellation (bool) – state of echo cancellation

>     - noise_suppression (bool) – state of noise suppression

>     - qos (bool) – state of voice quality of service

>     - silence_warning (bool) – state of silence warning notice

>     - deaf (bool) – state of self-deafen

>     - mute (bool) – state of self-mute

>   Return type:

>     pypresence.Response

> capture_shortcut(action)

>   Used to capture a keyboard shortcut entered by the user.

>   Parameters:

>     action (string) – capture action, either `'START'` or `'STOP'`

>   Return type:

>     pypresence.Response

> send_activity_join_invite(user_id)

>   Used to accept an Ask to Join request.

>   Parameters:

>     user_id (str) – user id

>   Return type:

>     pypresence.Response

> close_activity_request(user_id)

>   Used to reject an Ask to Join request.

>   Parameters:

>     user_id (str) – user id

>   Return type:

>     pypresence.Response

> register_event(event, func, args={})

>   Hook an event to a function. The function will be called whenever Discord sends that event. Will auto subscribe to it.

>   Parameters:

>     - event (str) – the event to hook

>     - func (function) – the function to pair with the event

>     - args (dict) – optional args used in subscription

>   Return type:

>     pypresence.Response

> unregister_event(event, args={})

>   Unhook an event from a function. Will auto unsubscribe from the event as well.

>   Parameters:

>     - event (str) – the event to unhook

>     - args (dict) – optional args used in unsubscription

>   Return type:

>     pypresence.Response