API Reference

The following section outlines the API of discord.py-oauth2 RPC extension.

Note

This module uses the Python logging module to log diagnostic and errors in an output independent way. If the logging module is not configured, these logs will not be output anywhere. See Setting Up Logging for more information on how to set up and use the logging module with discord.py-oauth2.

Clients

Client

Attributes
Methods
class discord.rpc.Client(*, transport='ipc', **options)

Represents a RPC client.

Note that to perform any operations with the Discord client you must call start() first.

pid

The ID of the current process.

Type

int

upgrade(*, intents=None)

This function is a coroutine.

Upgrades the RPC client to regular client.

Parameters

intents (Optional[Intents]) – The intents that you want to enable for the session. This is a way of disabling and enabling certain Gateway events from triggering and being sent.

Returns

The client.

Return type

discord.Client

await setup_hook()

This function is a coroutine.

A coroutine to be called to setup the client, by default this is blank.

To perform asynchronous setup after the client is logged in but before it has connected to the IPC socket, overwrite this coroutine.

This is only called once, in login(), and will be called before any events are dispatched, making it a better solution than doing such setup in the on_ready() event.

Warning

Since this is called before the IPC connection is made therefore anything that waits for the IPC will deadlock, this includes things like wait_for() and wait_until_ready().

await start(client_id, *, background=False, pipe=None, timeout=30.0)

This function is a coroutine.

Connects to the IPC socket.

Parameters
  • client_id (int) – The ID of the application.

  • background (bool) – Whether to connect to IPC socket and return task that will handle the socket flow.

  • pipe (Optional[int]) – The pipe to connect to.

  • timeout (Optional[float]) – The connection timeout in seconds.

Returns

The task that handles the flow.

Return type

Optional[asyncio.Task]

await close()

This function is a coroutine.

Closes the connection to Discord client.

clear()

Clears the internal state of the client.

After this, the client can be considered “re-opened”, i.e. is_closed() and is_ready() both return False along with the client’s internal cache cleared.

is_closed()

bool: Indicates if the IPC connection is closed.

property user

The currently connected user. None if not connected yet.

Type

Optional[ClientUser]

await edit_embedded_activity_config(*, use_interactive_pip)

This function is a coroutine.

Edits the configuration for current embedded activity.

Parameters

use_interactive_pip (bool) – Whether the picture-in-picture should be interactive.

Raises

RPCException – Editing the embedded activity configuration failed.

Returns

The newly updated embedded activity config.

Return type

EmbeddedActivityConfig

await authorize(client_id, *, response_type=<OAuth2ResponseType.code: 'code'>, scopes=None, code_challenge=None, code_challenge_method=None, state=None, nonce=None, permissions=None, guild=None, channel=None, prompt=None, disable_guild_select=None, install_type=None, pid=...)

This function is a coroutine.

Opens OAuth2 authorization modal in the Discord client.

Parameters
  • client_id (int) – The ID of the application being authorized.

  • response_type (Optional[OAuth2ResponseType]) – The type of response to return. Defaults to code.

  • scopes (Optional[List[str]]) – The scopes to authorize the application with.

  • code_challenge (Optional[str]) – A code challenge for the PKCE extension to the authorization code grant. Must be provided if using code_challenge_method.

  • code_challenge_method (Optional[OAuth2CodeChallengeMethod]) – The method used to generate the code challenge.

  • state (Optional[str]) – An unique string to bind the user’s request to their authenticated state.

  • nonce (Optional[str]) – An unique string to bind the user’s request to their authenticated state. Only applicable if requesting openid scope.

  • permissions (Optional[Permissions]) – The permissions to grant to the bot.

  • guild (Optional[Snowflake]) –

    The guild to pre-fill the dropdown picker with.

    Only applicable if requesting bot / applications.commands / webhook.incoming scope and install_type is guild.

  • channel (Optional[Snowflake]) –

    The channel to pre-fill the dropdown picker with.

    Only applicable if requesting webhook.incoming scope.

  • prompt (Optional[PromptBehavior]) – The prompt behavior to use for the authorization flow. Defaults to consent.

  • disable_guild_select (Optional[bool]) – Disallows the user from changing the guild dropdown. Only applicable when requesting bot / applications.commands / webhook.incoming scope and install_type is guild. Defaults to False.

  • install_type (Optional[InstallationType]) – The installation context for the authorization. Only applicable when requesting application.commands scope. Defaults to guild.

  • pid (Optional[int]) –

    The ID of the process to open the authorization modal in. If None wasn’t explicitly passed, this defaults to result of pid.

    If None is explicitly passed, then the modal will be open in existing Discord client instead.

Raises

RPCException – Authorizing the application failed.

Returns

The code that can be exchanged.

Return type

str

await authenticate(token)

This function is a coroutine.

Authenticates with the provided access token.

Note that you need to connect to IPC socket first using start().

Parameters

token (str) – The authentication token.

Raises

RPCException – Authenticating failed.

Returns

The current OAuth2 authorization and sanitized access token.

Return type

Tuple[OAuth2Authorization, str]

await fetch_guild(guild_id, *, timeout=None)

This function is a coroutine.

Retrieves a Guild with specified ID.

Parameters

guild_id (int) – The guild’s ID to request.

Raises

RPCException – Retrieving the guild failed.

Returns

The guild you requested.

Return type

Guild

await fetch_guilds()

This function is a coroutine.

Retrieves a list of guilds you’re in.

Raises

RPCException – Retrieving the guild list failed.

Returns

The guilds.

Return type

List[PartialGuild]

await fetch_channel(channel_id)

This function is a coroutine.

Retrieves a GuildChannel from specified ID.

Parameters

channel_id (int) – The channel’s ID to request.

Raises

RPCException – Retrieving the channel failed.

Returns

The guild channel you requested.

Return type

GuildChanenl

await fetch_guild_channels(guild_id)

This function is a coroutine.

Retrieves a list of channels the guild has.

Parameters

guild_id (int) – The guild’s ID to request channels of.

Raises

RPCException – Retrieving the guild channel list failed.

Returns

The guild channels.

Return type

List[PartialGuildChannel]

await fetch_current_channel_permissions()

This function is a coroutine.

Compute your permissions in the selected guild channel.

Raises

RPCException – Computing permissions failed.

Returns

The computed permissions.

Return type

Permissions

await create_channel_invite(channel_id)

This function is a coroutine.

Creates a invite in the specified channel.

Parameters

channel_id (int) – The channel’s ID to create the invite for.

Raises

RPCException – Creating the invite failed.

Returns

The created invite.

Return type

Invite

await fetch_relationships()

This function is a coroutine.

Retrieve all of your relationships and their presence.

Note that you will receive only overall status and discord.Relationship.activity will be not None if activity application is same as the authenticated application.

Raises

RPCException – Retrieving relationships failed.

Returns

The relationships.

Return type

List[Relationship]

await fetch_user(user_id)

This function is a coroutine.

Retrieve the specified user.

Parameters

user_id (int) – The user’s ID to request.

Raises

RPCException – Retrieving the user failed.

Returns

The user, if any.

Return type

Optional[User]

await add_subscription(subscription)

This function is a coroutine.

Adds an event subscription.

Parameters

subscription (EventSubscription) – The subscription to add.

Raises

RPCException – Adding an event subscription failed.

Returns

The event that the subscription just added.

Return type

str

await remove_subscription(subscription)

This function is a coroutine.

Removes an event subscription.

Parameters

subscription (EventSubscription) – The subscription to remove.

Raises

RPCException – Removing an event subscription failed.

Returns

The event that the subscription just removed.

Return type

str

await edit_user_voice_settings(user_id, *, pan=..., volume=..., mute=...)

This function is a coroutine.

Edits the voice settings for specified user.

You must have rpc or rpc.voice.write OAuth2 scope.

All parameters are optional.

Parameters
  • user_id (int) – The target user’s ID.

  • pan (Pan) – The new pan values for the target user.

  • volume (float) – The new local volume. Must be between 0 and 200.

  • mute (bool) – Whether the user should be muted.

Raises

RPCException – Editing the user voice settings failed.

Returns

The newly updated user voice settings.

Return type

UserVoiceSettings

await edit_user_voice_settings_2(user_id, *, volume=..., mute=...)

This function is a coroutine.

Edits the voice settings for specified user.

All parameters are optional.

Parameters
  • user_id (int) – The target user’s ID.

  • volume (float) – The new local volume. Must be between 0 and 200.

  • mute (bool) – Whether the user should be muted.

Raises

RPCException – Editing the user voice settings failed.

await push_to_talk(*, active=None)

This function is a coroutine.

Sets whether Push-To-Talk feature should be active.

Parameters

active (Optional[bool]) – Whether the Push-To-Talk feature should be active.

Raises

RPCException – Setting Push-To-Talk feature failed.

await select_voice_channel(channel_id, *, timeout=None, force=None, navigate=None)

This function is a coroutine.

Joins or leaves a voice channel.

Parameters
  • channel_id (Optional[int]) – The ID of the channel to join. Pass None to leave the current voice channel.

  • timeout (Optional[float]) – A timeout for joining/leaving voice channel in milliseconds.

  • force (Optional[bool]) – Whether to forcefully join/leave voice channel. Defaults to False.

  • navigate (Optional[bool]) – Whether to navigate to the voice channel after joining. Defaults to False.

Raises

RPCException – Joining/leaving the voice channel failed.

Returns

The voice channel that you joined.

Return type

Optional[GuildChannel]

await fetch_selected_voice_channel()

This function is a coroutine.

Retrieve the voice channel you’re currently in.

Raises

RPCException – Retrieving the current voice channel failed.

Returns

The voice channel you’re currently in, if any.

Return type

Optional[GuildChannel]

await select_text_channel(channel_id, *, timeout=None)

This function is a coroutine.

Navigates to a text channel.

Parameters
  • channel_id (Optional[int]) – The ID of the channel to navigate to. Pass None to leave the current text channel.

  • timeout (Optional[float]) – A timeout for navigating text channel in milliseconds.

Raises

RPCException – Navigating to text channel failed.

Returns

The text channel that you navigated to.

Return type

Optional[GuildChannel]

await fetch_voice_settings()

This function is a coroutine.

Retrieve your voice settings.

Raises

RPCException – Retrieving voice settings failed.

Returns

The voice settings.

Return type

VoiceSettings

await edit_voice_settings_2(*, input_mode=..., self_mute=..., self_deaf=...)

This function is a coroutine.

Edits the voice settings.

All parameters are optional.

Parameters
  • input_mode (VoiceInputMode) – The new input mode.

  • deaf (bool) – Indicates if you should be deafened by your accord.

  • mute (bool) – Indicates if you should be muted by your accord.

Raises

RPCException – Editing the voice settings failed.

await edit_voice_settings(*, input=..., output=..., mode=..., automatic_gain_control=..., echo_cancellation=..., noise_suppression=..., qos=..., silence_warning=..., deaf=..., mute=...)

This function is a coroutine.

Edits the voice settings.

All parameters are optional.

Parameters
  • input (VoiceIOSettings) – The new input settings.

  • output (VoiceIOSettings) – The new output settings.

  • mode (VoiceSettingsMode) – The new voice mode settings.

  • automatic_gain_control (bool) – Indicates if automatic gain control is enabled.

  • echo_cancellation (bool) – Indicates if echo cancellation is enabled.

  • noise_suppression (bool) – Indicates if the background noise is being suppressed.

  • qos (bool) – Indicates if Voice Quality of Service (QoS) is enabled.

  • silence_warning (bool) – Indicates if the silence warning notice is disabled.

  • deaf (bool) – Indicates if the user is deafened by their accord.

  • mute (bool) – Indicates if the user is muted by their accord.

Raises

RPCException – Editing the voice settings failed.

Returns

The newly updated voice settings.

Return type

VoiceSettings

await change_presence(*, activity=...)

This function is a coroutine.

Updates the current activity.

All parameters are optional.

Parameters

activity (Optional[Union[BaseActivity, Spotify]]) – The activity. Passing None denotes the activity will be removed.

Raises

RPCException – Changing the presence failed.

await send_activity_join_invite(to)

This function is a coroutine.

Sends an activity join invite to target user.

Parameters

to (Snowflake) – The user to send invite to.

Raises

RPCException – Sending the invite failed.

await reject_activity_join_request(from_)

This function is a coroutine.

Rejects an activity join request from the target user.

Parameters

from (Snowflake) – The user to reject the join request from.

await send_activity_invite(to, *, content=None)

This function is a coroutine.

Sends an activity invite to target user.

Parameters
  • to (Snowflake) – The user to send invite to.

  • content (Optional[str]) – The content to send with the invite.

Raises

RPCException – Sending the invite failed.

await accept_activity_invite(from_, *, session_id, channel_id, message_id, application_id=None)

This function is a coroutine.

Sends an activity invite to target user.

Parameters
  • to (Snowflake) – The user to send invite to.

  • content (Optional[str]) – The content to send with the invite.

Raises

RPCException – Sending the invite failed.

await open_invite_dialog()

This function is a coroutine.

Opens a modal to invite someone to the current voice channel.

Raises

RPCException – Opening the modal failed.

await open_share_moment_dialog(*, media_url)

This function is a coroutine.

Opens a modal to share media to a channel.

Parameters

media_url (str) – The URL to the media.

Raises

RPCException – Opening the modal failed.

await share_interaction(command, *, options=None, content=None, require_launch_channel=None, preview_image=None, components=None, pid=...)

This function is a coroutine.

Shares an interaction.

Parameters
  • command (str) – The name of the command to share.

  • options (Optional[Dict[str, str]]) – The options for the command.

  • content (Optional[str]) – The content. Can be only up to 2000 characters.

  • require_launch_channel (Optional[bool]) – Whether to require launching in channel.

  • preview_image (Optional[PreviewImage]) – The preview image.

  • components (Optional[List[Optional[List[Button]]]]) – The components. Rows can hold only up to 5 components.

  • pid (Optional[int]) – The ID of the process. If not provided, this defaults to pid.

Raises

RPCException – Sharing the interaction failed.

Returns

Whether the interaction was shared successfully.

Return type

bool

await initiate_image_upload()

This function is a coroutine.

Initiates the image upload flow.

Raises

RPCException – Initiating the image upload failed.

Returns

The URL to the image that was uploaded.

Return type

str

This function is a coroutine.

Shares a link.

Parameters
  • message (str) – The message. Can be only up to 1000 characters.

  • custom_id (Optional[str]) – The developer-defined ID for the link. Can be only up to 64 characters.

  • link_id (Optional[str]) – The developer-defined ID for the link. Can be only up to 64 characters.

Raises

RPCException – Sharing the link failed.

Returns

The result of sharing link.

Return type

SharedLink

await open_invite_modal(code)

This function is a coroutine.

Opens a invite modal in the Discord client.

Parameters

code (str) – The code.

Raises

RPCException – Opening the invite modal failed.

Returns

The invite.

Return type

Tuple[str, Invite]

This function is a coroutine.

Opens a deep link.

Parameters
  • location (DeepLinkLocation) – The location.

  • params (Any) – The parameters for the deep link.

Raises

RPCException – Opening the deep link failed.

Returns

Unknown.

Return type

Optional[bool]

await trigger_connections_callback(code, *, type, openid_params=None, issuer=None, state)

This function is a coroutine.

Triggers the connections callback.

Parameters
  • code (str) – The code.

  • type (ConnectionType) – The connection type.

  • openid_params (Optional[str]) – The OpenID parameters.

  • issuer (Optional[str]) – The issuer.

  • state (str) – The state.

Raises

RPCException – Triggering the connections callback failed.

await trigger_billing_popup_bridge_callback(path, *, payment_source_type, query=None, state)

This function is a coroutine.

Triggers the billing popup bridge callback.

Parameters
  • path (str) – The path.

  • payment_source_type (PaymentSourceType) – The payment source type.

  • query (Optional[Dict[str, str]]) – The parameters.

  • state (str) – The state.

Raises

RPCException – Triggering the billing popup bridge callback failed.

await trigger_braintree_popup_bridge_callback(path, *, query=None, state)

This function is a coroutine.

Triggers the Braintree popup bridge callback.

Parameters
  • path (str) – The path.

  • query (Optional[Dict[str, str]]) – The parameters.

  • state (str) – The state.

Raises

RPCException – Triggering the Braintree popup bridge callback failed.

await fetch_gift(code)

This function is a coroutine.

Retrieves a gift.

Parameters

code (str) – The code of the gift.

Raises

RPCException – Retrieving the gift failed.

Returns

The gift.

Return type

Gift

await fetch_template(code)

This function is a coroutine.

Retrieves a template.

Parameters

code (str) – The code of the template.

Raises

RPCException – Retrieving the template failed.

Returns

The template.

Return type

Template

await open_message(channel_id, message_id, *, guild_id=..., pid=...)

This function is a coroutine.

Jumps to a message.

Parameters
  • channel_id (int) – The ID of the channel the message was sent in.

  • message_id (int) – The ID of the message to jump to.

  • guild_id (Optional[int]) – The ID of the guild the message was sent in.

  • pid (int) – The ID of the process. Defaults to pid.

Raises

RPCException – Jumping to the message failed.

await suppress_notifications(value, *, target_user_id)

This function is a coroutine.

Sets whether the notifications from specified user are suppressed.

Parameters
  • value (bool) – Indicates if notifications are suppressed.

  • target_user_id (int) – The ID of the user to suppress notifications from.

Raises

RPCException – Setting failed.

await overlay(token)

This function is a coroutine.

Activates the overlay.

Parameters

token (str) – The token for activating the overlay.

Raises

RPCException – Activating the overlay failed.

await handoff(token, *, fingerprint)

This function is a coroutine.

Ends the browser handoff flow.

Parameters
  • token (str) – The handoff token.

  • fingerprint (str) – The fingerprint.

Raises

RPCException – Ending the browser handoff flow failed.

await set_certified_devices(*devices)

This function is a coroutine.

Send current information about certified devices.

Parameters

*devices (CertifiedDevice) – The devices.

Raises

RPCException – Setting the certified devices failed.

await fetch_image(id, *, format='png', size=512)

This function is a coroutine.

Retrieves a image.

Parameters
  • id (str) – The ID of the image.

  • format (str) – The format of the image. Currently can be only png, webp, or jpg.

  • size (int) – The size of the image. Currently can be only 16, 32, 64, 128, 256, 512, or 1024.

Raises

RPCException – Retrieving the image failed.

Returns

The data URL of the image.

Return type

str

await set_overlay_locked(value, *, pid=...)

This function is a coroutine.

Sets whether the overlay is locked.

Parameters
  • value (bool) – Indicates if the overlay is locked.

  • pid (int) – The ID of the process the overlay is running in. Defaults to pid.

Raises

RPCException – Setting failed.

await open_overlay_activity_invite(*, pid=...)

This function is a coroutine.

Opens the activity invite in overlay.

Parameters

pid (int) – The ID of the process the overlay is running in. Defaults to pid.

Raises

RPCException – Opening failed.

await open_overlay_guild_invite(code, *, pid=...)

This function is a coroutine.

Opens the guild invite in overlay.

Parameters
  • code (str) – The invite code.

  • pid (int) – The ID of the process the overlay is running in. Defaults to pid.

Raises

RPCException – Opening failed.

await open_overlay_voice_settings(*, pid=...)

This function is a coroutine.

Opens the voice settings in overlay.

Parameters

pid (int) – The ID of the process the overlay is running in. Defaults to pid.

Raises

RPCException – Opening failed.

await validate_application()

This function is a coroutine.

Validates the application.

Raises

RPCException – Validating the application failed.

Returns

Whether the application is valid.

Return type

Optional[bool]

await fetch_entitlement_ticket()

This function is a coroutine.

Retrieve an entitlement ticket.

Raises

RPCException – Retrieving the entitlement ticket failed.

Returns

The entitlement ticket.

Return type

str

await fetch_application_ticket()

This function is a coroutine.

Retrieve an application ticket.

Raises

RPCException – Retrieving the application ticket failed.

Returns

The application ticket.

Return type

str

await start_purchase(sku_id, *, pid=...)

This function is a coroutine.

Starts a SKU purchase flow.

Parameters
  • sku_id (int) – The ID of the SKU to purchase.

  • pid (Optional[int]) – The ID of the process to start flow in.

Raises

RPCException – Starting the SKU purchase flow failed.

Returns

The entitlements.

Return type

List[Entitlement]

await start_premium_purchase(*, pid=...)

This function is a coroutine.

Starts a premium purchase flow.

Parameters

pid (Optional[int]) – The ID of the process to start flow in.

Raises

RPCException – Starting the premium purchase flow failed.

await fetch_skus(*, embedded=False)

This function is a coroutine.

Retrieve the application’s SKUs.

Parameters

embedded (bool) – Whether the application is embedded into the Discord client.

Returns

The SKUs the application has.

Return type

List[SKU]

await fetch_entitlements(*, embedded=False)

This function is a coroutine.

Retrieve the entitlements you have associated with the current application.

Parameters

embedded (bool) – Whether the application is embedded into the Discord client.

Returns

The entitlements you have.

Return type

List[Entitlement]

await fetch_networking_config()

This function is a coroutine.

Retrieve the user’s networking config.

Raises

RPCException – Retrieving the networking config failed.

Returns

A (address, token) tuple.

Return type

Tuple[str, str]

await track_networking_system_metrics()

This function is a coroutine.

Tracks the networking system metrics.

Raises

RPCException – Tracking failed.

await track_networking_peer_metrics()

This function is a coroutine.

Tracks the networking system metrics.

Raises

RPCException – Tracking failed.

await create_networking_token()

This function is a coroutine.

Retrieve a networking token.

Raises

RPCException – Creating the networking token failed.

Returns

The networking token.

Return type

str

await fetch_user_locale()

This function is a coroutine.

Retrieve the user’s current locale.

Raises

RPCException – Retrieving the user’s locale failed.

Returns

The user’s current locale.

Return type

Locale

await send_analytics_event(name, properties)

This function is a coroutine.

Send analytics event.

Parameters
  • name (str) – The name of the analytics event.

  • properties (Dict[str, Any]) – The properties of the analytics event.

Raises

RPCException – Sending the analytics event failed.

This function is a coroutine.

Opens the external link.

Parameters

url (str) – The URL to open.

Raises

RPCException – Opening the external link failed.

Returns

Whether the URL was opened.

Return type

bool

await capture_log_entry(message, *, level=<LogLevel.log: 'log'>)

This function is a coroutine.

Capture a log entry.

Parameters
  • message (str) – The message. Can be only up to 1000 characters.

  • level (LogLevel) – The log level.

Raises

RPCException – Capturing the log entry failed.

await encourage_hardware_acceleration()

This function is a coroutine.

Opens a modal in the Discord client to encourage enabling hardware acceleration.

Raises

RPCException – Opening the modal failed.

Returns

Indicates if hardware acceleration was enabled.

Return type

bool

await edit_orientation_lock_state(lock_state, *, pip_lock_state=..., grid_lock_state=...)

This function is a coroutine.

Edits the orientation lock state.

Parameters
Raises

RPCException – Editing the orientation lock state failed.

await fetch_platform_behaviors()

This function is a coroutine.

Retrieve behaviors for the current platform.

Raises

RPCException – Retrieving the behaviors failed.

Returns

The platform behaviors.

Return type

PlatformBehaviors

await fetch_soundboard_sounds()

This function is a coroutine.

Retrieve soundboard sounds from all guilds (including default ones).

Raises

RPCException – Retrieving the soundboard sounds failed.

Returns

The sounds.

Return type

List[Union[SoundboardDefaultSound, SoundboardSound]]

await play_soundboard_sound(sound_id=None, *, guild_id=None)

This function is a coroutine.

Plays the soundboard sound in the current channel.

Parameters
  • sound_id (Optional[int]) – The ID of the sound.

  • guild_Id (Optional[int]) – The ID of the guild the sound is from.

Raises

RPCException – Playing the soundboard sound failed.

await toggle_video()

This function is a coroutine.

Toggles the video display.

Raises

RPCException – Toggling disabled.

await toggle_screenshare(*, pid=...)

This function is a coroutine.

Toggles the screenshare display.

Parameters

pid (Optional[int]) – The ID of the process to screenshare. Defaults to pid.

Raises

RPCException – Toggling disabled.

await fetch_activity_instance_participants()

This function is a coroutine.

Retrieve a list of connected users participanting in the current activity instance.

Raises

RPCException – Retrieving the connected activity instance participants failed.

Returns

The participants.

Return type

List[ActivityParticipant]

await fetch_provider_access_token(provider, *, connection_redirect=None)

This function is a coroutine.

Retrieve access token for a specified provider.

Parameters
  • provider (discord.ConnectionType) – The provider to retrieve access token for.

  • connection_redirect (Optional[str]) – The URL to redirect to.

Raises

RPCException – Retrieving the access token failed.

Returns

The retrieved access token.

Return type

str

await maybe_fetch_provider_access_token(provider)

This function is a coroutine.

Retrieve refresh token for a specified provider.

Parameters

provider (ConnectionType) – The provider to retrieve refresh token for.

Raises

RPCException – Retrieving the refresh token failed.

Returns

The retrieved refresh token.

Return type

str

await navigate_to_connections()

This function is a coroutine.

Navigates to the “Connections” page.

Raises

RPCException – Navigating failed.

await invite_user_embedded(content=None, *, to)

This function is a coroutine.

Invites the target user to running activity.

Parameters
  • content (Optional[str]) – The message content. Can be only up to 1024 characters.

  • to (Snowflake) – The user to send the invite to.

Raises

RPCException – Inviting the user failed.

dispatch(event, /, *args, **kwargs)

Dispatch an event.

Examples

Dispatch an mention event when client is mentioned in a message:

@client.event
async def on_message(message):
    if client.user.mentioned_in(message):
        client.dispatch('mention', message)

@client.event
async def on_mention(message):
    print(f'I was mentioned in message by {message.author.name}!')
Parameters
  • event (str) – The event to dispatch. Do not prefix this with on_ as library will do it for you.

  • *args (Any) – The event positional arguments.

  • **kwargs (Any) – The event keyword arguments.

event(coro, /)

A decorator that registers an event to listen to.

You can find more info about the events on the documentation below.

The events must be a coroutine, if not, TypeError is raised.

Example

@client.event
async def on_ready():
    print('Ready!')

Changed in version 2.0: coro parameter is now positional-only.

Raises

TypeError – The coroutine passed is not actually a coroutine.

await fetch_quest_enrollment_status(quest_id)

This function is a coroutine.

Retrieves enrollment status for a quest.

Parameters

quest_id (int) – The quest’s ID to retrieve enrollment status for.

Raises

RPCException – Retrieving the quest enrollment status failed.

Returns

The enrollment status for quest.

Return type

QuestEnrollmentStatus

await on_error(event_method, /, *args, **kwargs)

This function is a coroutine.

The default error handler provided by the client.

By default this logs to the library logger however it could be overridden to have a different implementation. Check on_error() for more details.

Changed in version 2.0: event_method parameter is now positional-only and instead of writing to sys.stderr it logs instead.

await start_quest_timer(quest_id)

This function is a coroutine.

Starts the timer for a quest.

Parameters

quest_id (int) – The quest’s ID to start timer for.

Raises

RPCException – Starting the quest timer failed.

Returns

Whether the timer was successfully started.

Return type

bool

Event Reference

This section outlines the different types of events listened by Client.

There are two ways to register an event, the first way is through the use of Client.event(). The second way is through subclassing Client and overriding the specific events. For example:

import discord.rpc

class MyClient(discord.rpc.Client):
    async def on_ready(self):
        await self.add_subscription(discord.rpc.ChannelSubscription.message_create(98765432123456789))

    async def on_message(self, message):
        if message.author == self.user:
            return

        if message.content.startswith('$hello'):
            print('Someone sent hello!')

If an event handler raises an exception, on_error() will be called to handle it, which defaults to logging the traceback and ignoring the exception.

Warning

All the events must be a coroutine. If they aren’t, then you might get unexpected errors. In order to turn a function into a coroutine they must be async def functions.

Note

To listen to an event, you must subscribe to it using Client.add_subscription(). To unsubscribe from an event, use Client.remove_subscription().

IPC

discord.rpc.on_ready()

Called when the client is done preparing the data received from Discord.

discord.rpc.on_authorize_request()

Called when the client wants to authorize.

Current User

discord.rpc.on_current_user_update(before, after)

Called when a ClientUser updates their profile.

This is called when one or more of the following things change:

  • avatar

  • username

  • discriminator

Parameters
discord.rpc.on_current_member_update(member)

Called when a Member belonging to the current user updates their profile.

Parameters

member (Member) – The updated member’s updated info.

Guilds

discord.rpc.on_guild_update(guild)

Called when a PartialGuild updates, for example:

  • Changed name

  • Changed icon

Parameters

guild (PartialGuild) – The guild after being updated.

discord.rpc.on_guild_join(guild)

Called when a PartialGuild is either created by the Client or when the Client joins a guild.

Parameters

guild (PartialGuild) – The guild that was joined.

Channels

discord.rpc.on_guild_channel_create(channel)
discord.rpc.on_private_channel_create(channel)

Called whenever a guild / private channel is created.

Parameters

channel (PartialChannel) – The channel that got created.

Relationships

discord.rpc.on_relationship_update(relationship)

Called when a discord.Relationship is updated, e.g. when you block a friend or a friendship is accepted.

Parameters

relationship (discord.Relationship) – The updated relationship.

Voice Channels

discord.rpc.on_voice_channel_select(channel_id, guild_id)

Called when the current user moves between voice channels.

Parameters
  • channel_id (Optional[int]) – The ID of the channel the user joined.

  • guild_id (Optional[int]) – The ID of the guild the channel is in.

discord.rpc.on_voice_state_create(voice_state)
discord.rpc.on_voice_state_update(voice_state)
discord.rpc.on_voice_state_delete(voice_state)

Called whenever a voice state is created, updated or deleted.

Parameters

voice_state (VoiceState) – The voice state that got created, updated or deleted.

Settings

discord.rpc.on_voice_settings_update(voice_settings)

Called whenever the voice settings are updated.

Parameters

voice_settings (VoiceSettings) – The updated voice settings.

discord.rpc.on_voice_connection_status_update(voice_connection_status)

Called whenever a voice connection changes it’s status.

Parameters

voice_connection_status (VoiceConnectionStatus) – The current voice connection status.

Voice

discord.rpc.on_speaking_start(channel_id, user_id)
discord.rpc.on_speaking_stop(channel_id, user_id)

Called whenever an user starts / stops speaking in a voice channel.

Parameters
  • channel_id (int) – The ID of the voice channel.

  • user_id (int) – The ID of the user that started / stopped speaking.

Activities

discord.rpc.on_game_join(secret, intent)

Called whenever an user joins a game.

Deprecated since version 3.0: Use on_activity_join() instead.

Parameters
  • secret (str) – The secret for joining the game.

  • intent (Optional[JoinIntent]) – The intent for joining the game. Only applicable if the application is embedded into the Discord client.

discord.rpc.on_activity_join(secret, intent)

Called whenever an user joins an activity.

Parameters
  • secret (str) – The secret for joining the activity.

  • intent (Optional[JoinIntent]) – The intent for joining the activity. Only applicable if the application is embedded into the Discord client.

discord.rpc.on_activity_invite(invite)

Called whenever the current user receives a invite to join an activity.

Parameters

invite (discord.ActivityInvite) – The activity invite.

discord.rpc.on_pip_mode_update(is_pip_mode)

Called whenever PiP (Picture-in-Picture) mode changes.

Parameters

is_pip_mode (bool) – Indicates if the current layout mode is PiP.

discord.rpc.on_layout_mode_update(layout_mode)

Called whenever the activity layout mode changes.

Parameters

layout_mode (LayoutMode) – The current layout mode.

discord.rpc.on_thermal_state_update(thermal_state)

Called whenever the thermal state changes.

Parameters

thermal_state (ThermalState) – The current thermal state.

discord.rpc.on_orientation_update(screen_orientation)

Called whenever the screen orientation changes.

Parameters

screen_orientation (OrientationLockState) – The current screen orientation.

discord.rpc.on_raw_activity_instance_participants_update(participants)

Called whenever an user joins/leaves the activity instance.

Parameters

participants (List[ActivityParticipant]) – The current list of activity participants.

Notifications

discord.rpc.on_notification(notification)

Called whenever the current user receives a notification.

Parameters

notification (Notification) – The notification.

Messages

discord.rpc.on_message(message)

Called when a Message is created and sent.

Warning

Your client’s own messages and private messages are sent through this event. This can lead cases of ‘recursion’ depending on how your client was programmed. If you want the client to not reply to itself, consider checking the user IDs.

Parameters

message (Message) – The message received.

discord.rpc.on_message_edit(message)

Called when a Message receives an update event.

The following non-exhaustive cases trigger this event:

  • A message has been pinned or unpinned.

  • The message content has been changed.

  • The message has received an embed.

    • For performance reasons, the embed server does not do this in a “consistent” manner.

  • The message’s embeds were suppressed or unsuppressed.

  • A call message has received an update to its participants or ending time.

Parameters

message (Message) – The current version of the message.

discord.rpc.on_message_delete(channel_id, message_id)

Called when a message is deleted.

Parameters
  • channel_id (int) – The ID of the channel the deleted message was sent in.

  • message_id (int) – The ID of the deleted message.

Entitlements

discord.rpc.on_entitlement_create(entitlement)

Called when the current user subscribes to a SKU.

Parameters

entitlement (discord.Entitlement) – The entitlement that was created.

discord.rpc.on_entitlement_update(entitlement)

Called when the current user updates their subscription to a SKU. This is usually called when the user renews or cancels their subscription.

Parameters

entitlement (discord.Entitlement) – The entitlement that was updated.

discord.rpc.on_entitlement_delete(entitlement)

Called when an users subscription to a SKU is cancelled. This is typically only called when:

  • Discord issues a refund for the subscription.

  • Discord removes an entitlement from a user.

Warning

This event won’t be called if the user cancels their subscription manually, instead on_entitlement_update() will be called with ends_at set to the end of the current billing period.

Parameters

entitlement (discord.Entitlement) – The entitlement that was deleted.

Video

discord.rpc.on_screenshare_state_update(active, pid, application_name)

Called whenever screenshare state changes.

Parameters
  • active (bool) – Indicates if the screenshare video is still active.

  • pid (Optional[int]) – The ID of the process whose screen is being shared.

  • application_name (Optional[str]) – The name of the application.

discord.rpc.on_video_state_update(active)

Called whenever video state changes.

Parameters

active (bool) – Indicates if the video is still active.

Quests

discord.rpc.on_quest_enrollment_status_update(status)

Called whenever quest enrollment status changes.

Parameters

status (QuestEnrollmentStatus) – The current status of quest enrollment.

Enumerations

The RPC API provides some enumerations for certain types of strings to avoid the API from being stringly typed in case the strings change in the future.

All enumerations are subclasses of an internal class which mimics the behaviour of enum.Enum.

class discord.rpc.CertifiedDeviceType

Specifies the type of certified device.

audio_input

The device accepts audio as input.

audio_output

The device generates audio as output.

video_input

The device accepts video as input.

class discord.rpc.DeepLinkLocation

Specifies the type of deep link.

user_settings

The deep link navigates to the user settings.

changelog

The deep link navigates to the changelogs.

library

The deep link navigates to the game library.

store_home

The deep link navigates to store.

store_listing

The deep link navigates to a store listing.

pick_guild_settings

The deep link navigates to picking settings for a guild.

channel

The deep link navigates to channel or message.

quest_home

The deep link navigates to Quests.

discovery_game_results

oauth2

The deep link navigates to Authorized Apps.

shop

The deep link navigates to shop.

features

The deep link navigates to features.

activities

The deep link navigates to activities.

class discord.rpc.JoinIntent

Specifies the type of join intent.

play

The user wants to play.

spectate

The user wants to spectate.

class discord.rpc.LayoutMode

Specifies the layout mode.

focused

The activity is focused.

pip

The activity is in picture in an another picture.

grid

The activity is placed in a grid.

class discord.rpc.LogLevel

Specifies the logging level.

log

Use console.log for logging.

warn

Use console.warn for logging.

debug

Use console.debug for logging.

info

Use console.info for logging.

error

Use console.error for logging.

class discord.rpc.Opcode

Specifies the RPC socket opcode.

handshake

Start RPC socket handshake.

frame

Send a command.

close

The RPC socket is closing.

ping

The RPC socket requests you to send pong.

pong

The RPC socket is responding to ping.

class discord.rpc.OrientationLockState

Specifies the state of orientation.

unlocked

The orientation is unlocked.

portrait

The orientation is in portrait.

landscape

The orientation is in landscape.

class discord.rpc.PromptBehavior

Specifies the behavior of prompt.

none

Skips the authorization screen and immediately redirects the user. Requires previous authorization with the requested scopes.

consent

Prompts the user to re-approve their authorization.

class discord.rpc.ShortcutKeyComboType

Specifies the type of shortcut key combo.

keyboard_key

The combo is binded to a keyboard key.

mouse_button

The combo is binded to a mouse button.

keyboard_modifier_key

The combo is binded to a keyboard modifier key.

gamepad_button

The combo is binded to a gamepad button.

class discord.rpc.ThermalState

Specifies the thermal state.

nominal

The thermal state is currently nominal.

fair

The thermal state is currently fair.

serious

The thermal state is serious.

critical

The thermal state is critical.

class discord.rpc.VoiceConnectionState

Specifies the state of voice connection.

disconnected

The voice server is disconnected.

awaiting_endpoint

The client is waiting for a voice endpoint.

authenticating

Discord has connected to your real-time communication server and is currently securing the connection.

connecting

A RTC server has been allocated and Discord is attempting to connect to it.

rtc_disconnected

A connection has been interrupted. Discord will attempt to re-establish the connection in a moment.

rtc_connecting

A secure connection to real-time communication server is established and attempting to send data.

rtc_connected

no_route

The connection cannot be established. Discord will try again in a moment.

ice_checking

A secure connection to real-time communication server is established and attempting to send data.

dtls_conneccting

A secure connection to real-time communication server is established and attempting to send data.

class discord.rpc.VoiceSettingsModeType

Specifies the type of voice settings mode.

ptt

Push-To-Talk.

voice_activity

Voice activity.

Discord Models

Models are classes that are received from Discord and are not meant to be created by the user of the library.

Danger

The classes listed below are not intended to be created by users and are also read-only.

For example, this means that you should not make your own ActivityParticipant instances nor should you modify the ActivityParticipant instance yourself.

If you want to get one of these model classes instances they’d have to be through the cache, and a common way of doing so is through the utils.find() function or attributes of model classes that you receive from the events specified in the Event Reference.

Note

Nearly all classes here have __slots__ defined which means that it is impossible to have dynamic attributes to the data classes.

ActivityParticipant

class discord.rpc.ActivityParticipant

Represents an activity participant.

Same as User, except with additional nickname attribute.

nickname

The nickname that the user has for the current guild.

Type

Optional[str]

property accent_color

Returns the user’s accent color, if applicable.

A user’s accent color is only shown if they do not have a banner. This will only be available if the user explicitly sets a color.

There is an alias for this named accent_colour.

New in version 2.0.

Note

This information is only available via discord.Client.fetch_user().

Type

Optional[discord.Color]

property accent_colour

Returns the user’s accent colour, if applicable.

A user’s accent colour is only shown if they do not have a banner. This will only be available if the user explicitly sets a colour.

This is an alias of accent_color.

New in version 2.0.

Note

This information is only available via discord.Client.fetch_user().

Type

Optional[discord.Color]

property avatar

Returns an Asset for the avatar the user has.

If the user has not uploaded a global avatar, None is returned. If you want the avatar that a user has displayed, consider display_avatar.

Type

Optional[discord.Asset]

property avatar_decoration

Returns an Asset for the avatar decoration the user has.

If the user has not set an avatar decoration, None is returned.

New in version 2.4.

Type

Optional[discord.Asset]

property avatar_decoration_sku_id

Returns the SKU ID of the avatar decoration the user has.

If the user has not set an avatar decoration, None is returned.

New in version 2.4.

Type

Optional[int]

property banner

Returns the user’s banner asset, if available.

New in version 2.0.

Note

This information is only available via discord.Client.fetch_user().

Type

Optional[discord.Asset]

await block()

This function is a coroutine.

Blocks the user.

Raises
property color

A property that returns a color denoting the rendered color for the user. This always returns Color.default().

There is an alias for this named colour.

Type

discord.Color

property colour

A property that returns a colour denoting the rendered colour for the user. This always returns Colour.default().

This is an alias of color.

Type

discord.Colour

await create_dm()

This function is a coroutine.

Creates a discord.DMChannel with this user.

This should be rarely called, as this is done transparently for most people.

Returns

The channel that was created.

Return type

Union[DMChannel, EphemeralDMChannel]

property created_at

Returns the user’s creation time in UTC.

This is when the user’s Discord account was created.

Type

datetime.datetime

property default_avatar

Returns the default avatar for a given user.

Type

discord.Asset

property display_avatar

Returns the user’s display avatar.

For regular users this is just their default avatar or uploaded avatar.

New in version 2.0.

Type

discord.Asset

property display_name

Returns the user’s display name.

For regular users this is just their global name or their username, but if they have a guild specific nickname then that is returned instead.

Type

str

property dm_channel

Returns the channel associated with this user if it exists.

If this returns None, you can create a DM channel by calling the create_dm() coroutine function.

Type

Optional[Union[DMChannel, EphemeralDMChannel]]

property game_relationship

Returns the GameRelationship with this user if applicable, None otherwise.

Type

Optional[GameRelationship]

is_blocked()

bool: Checks if the user is blocked.

is_friend()

bool: Checks if the user is your friend.

is_game_friend()

bool: Checks if the user is your friend in-game.

is_ignored()

bool: Checks if the user is ignored.

property mention

Returns a string that allows you to mention the given user.

Type

str

mentioned_in(message)

Checks if the user is mentioned in the specified message.

Parameters

message (discord.Message) – The message to check if you’re mentioned in.

Returns

Indicates if the user is mentioned in the message.

Return type

bool

property mutual_groups

The groups that the user shares with the client.

Note

This will only return mutual groups within the client’s internal cache.

Type

List[GroupChannel]

property mutual_guilds

The guilds that the user shares with the client.

Note

This will only return mutual guilds within the client’s internal cache.

New in version 1.7.

Type

List[discord.Guild]

property primary_guild

Returns the user’s primary guild.

Type

discord.PrimaryGuild

property public_flags

The publicly available flags the user has.

Type

discord.PublicUserFlags

property relationship

Returns the Relationship with this user if applicable, None otherwise.

Type

Optional[Relationship]

await remove_friend()

This function is a coroutine.

Removes the user as a friend.

Raises
  • Forbidden – Not allowed to remove this user as a friend.

  • HTTPException – Removing the user as a friend failed.

await remove_game_friend()

This function is a coroutine.

Removes the user as a in-game friend.

Raises
  • Forbidden – Not allowed to remove this user as a in-game friend.

  • HTTPException – Removing the user as a in-game friend failed.

await send(content=None, *, file=None, files=None, delete_after=None, allowed_mentions=None, metadata=...)

This function is a coroutine.

Sends a message to the destination with the content given.

The content must be a type that can convert to a string through str(content). If the content is set to None (the default), then the embed parameter must be provided.

To upload a single file, the file parameter should be used with a single File object. To upload multiple files, the files parameter should be used with a list of File objects. Specifying both parameters will lead to an exception.

Changed in version 2.0: This function will now raise TypeError or ValueError instead of InvalidArgument.

Parameters
  • content (Optional[str]) – The content of the message to send.

  • file (File) – The file to upload.

  • files (List[File]) – A list of files to upload. Must be a maximum of 10.

  • delete_after (float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.

  • allowed_mentions (AllowedMentions) –

    Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

    New in version 1.4.

  • metadata (Optional[Dict[str, str]]) – The message’s metadata. Can be only up to 25 entries, and 1024 characters per key and value.

Raises
  • HTTPException – Sending the message failed.

  • Forbidden – You do not have the proper permissions to send the message.

  • NotFound – You sent a message with the same nonce as one that has been explicitly deleted shortly earlier.

  • ValueError – The files list is not of the appropriate size.

  • TypeError – You specified both file and files.

Returns

The message that was sent.

Return type

Message

await send_friend_request()

This function is a coroutine.

Sends the user a friend request.

Raises
  • Forbidden – Not allowed to send a friend request to the user.

  • HTTPException – Sending the friend request failed.

await send_game_friend_request()

This function is a coroutine.

Sends the user a in-game friend request.

Raises
  • Forbidden – Not allowed to send a game friend request to the user.

  • HTTPException – Sending the game friend request failed.

await unblock()

This function is a coroutine.

Unblocks the user.

Raises
property voice

Returns the user’s current voice state.

Type

Optional[discord.VoiceState]

PartialChannel

Attributes
class discord.rpc.PartialChannel

Represents a partial Discord channel.

New in version 3.0.

id

The channel’s ID.

Type

int

guild_id

The guild’s ID that this channel belongs to (or zero if the channel is a private channel).

Type

int

type

The channel’s type.

Type

discord.ChannelType

name

The channel’s name. Empty for DM channels.

Type

str

property guild

The guild that this channel belongs to.

Type

Optional[Guild]

GuildChannel

class discord.rpc.GuildChannel

Represents a Discord guild channel.

This inherits from PartialChannel.

New in version 3.0.

topic

The channel’s topic.

Type

str

bitrate

The channel’s preferred audio bitrate in bits per second. Only applicable if the channel is vocal (voice or stage) channel.

Type

int

user_limit

The channel’s limit for number of members that can be in a vocal channel. Only applicable if the channel is vocal (voice or stage) channel.

Type

int

position

The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0.

Type

int

messages

A list of messages in channel. May be empty if the user have not visited the channel.

Type

List[Message]

voice_states

A list of voice states that belong to this channel. Only applicable if the channel is vocal (voice or stage) channel.

Type

List[VoiceState]

property guild

The guild that this channel belongs to.

Type

Optional[Guild]

PlatformBehaviors

class discord.rpc.PlatformBehaviors

Represents behaviors for various platforms.

ios_keyboard_resizes_view

indicates if keyboard on iOS resizes view.

Type

bool

EmbeddedActivityConfig

Attributes
class discord.rpc.EmbeddedActivityConfig

Represents configuration for an embedded activtiy.

use_interactive_pip

Whether the picture-in-picture is interactive.

Type

bool

PartialGuild

class discord.rpc.PartialGuild

Represents a Discord guild.

This inherits from discord.PartialGuild, and unlike the inherited class, these are received over RPC and will have following attributes filled in:

await change_voice_state(*, channel, self_mute=False, self_deaf=False, self_video=False)

This function is a coroutine.

Changes client’s voice state in the guild.

New in version 1.4.

Parameters
  • channel (Optional[Snowflake]) – Channel the client wants to join. You must explicitly pass None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

  • self_video (bool) – Indicates if the client should show camera.

await create_command(name, *, name_localizations=..., description=..., description_localizations=..., options=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=..., type=<AppCommandType.chat_input: 1>)

This function is a coroutine.

Creates an application command for the guild.

New in version 3.0.

Parameters
  • name (str) – The name for the slash command. Must be between 1 and 32 characters long.

  • name_localizations (Optional[Dict[Locale, str]]) –

    The name localizations for the slash command.

    Each value must be between 1 and 32 characters.

  • description (Optional[str]) – The description for the slash command. Can be only up to 100 characters.

  • description_localizations (Optional[Dict[Locale, str]]) –

    The description localizations for the slash command.

    Each value can be only up to 100 characters.

  • options (List[Union[Option, SlashCommandGroup]]) – The options for the slash command.

  • default_member_permissions (Optional[Permissions]) – The default permissions needed to use this application command. Pass value of None to remove any permission requirements.

  • dm_permission (bool) –

    Indicates if the application command can be used in DMs.

    Deprecated since version 3.0: Edit allowed_contexts instead.

  • allowed_contexts (Optional[AppCommandContext]) – The contexts that this command should be allowed to be used in. Overrides the dm_permission parameter.

  • allowed_installs (Optional[AppInstallationType]) – The installation contexts that this command should be allowed to be installed in.

  • type (AppCommandType) – The type for the application command. Defaults to chat_input.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The application command created.

Return type

Union[SlashCommand, UserCommand, MessageCommand]

await create_message_command(name, *, name_localizations=..., description=..., description_localizations=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=...)

This function is a coroutine.

Creates a message command for the guild.

The parameters are same as create_command() except options is removed.

New in version 3.0.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The message command created.

Return type

MessageCommand

await create_slash_command(name, *, name_localizations=..., description=..., description_localizations=..., options=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=...)

This function is a coroutine.

Creates a slash command for the guild.

The parameters are same as create_command().

New in version 3.0.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The slash command created.

Return type

SlashCommand

await create_user_command(name, *, name_localizations=..., description=..., description_localizations=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=...)

This function is a coroutine.

Creates an user command for the guild.

The parameters are same as create_command() except options is removed.

New in version 3.0.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The user command created.

Return type

UserCommand

property created_at

Returns the guild’s creation time in UTC.

Type

datetime.datetime

await fetch_command(id, /)

This function is a coroutine.

Fetches an application command from the application.

Parameters

id (int) – The ID of the command to fetch.

Raises
  • HTTPException – Fetching the command failed.

  • MissingApplicationID – The application ID could not be found.

  • NotFound – The application command was not found. This could also be because the command is a global command.

Returns

The retrieved command.

Return type

Union[SlashCommand, UserCommand, MessageCommand, UnknownCommand]

await fetch_commands()

This function is a coroutine.

Fetches the application’s current commands.

Raises
Returns

The application’s commands.

Return type

List[Union[SlashCommand, UserCommand, MessageCommand, UnknownCommand]]

await fetch_me()

This function is a coroutine.

Retrieve member version of yourself for this guild.

Similar to Client.fetch_me() except returns Member. This is essentially used to get the member version of yourself.

Raises
  • Forbidden – You do not have proper permissions to fetch member version of yourself for this guild.

  • HTTPException – Retrieving member version of yourself failed.

Returns

The member version of yourself.

Return type

Member

get_partial_message_command(id, /, *, application_id=None)

Retrieve a very partial message command that can be used to edit or delete the guild command.

Parameters
  • id (int) – The ID of the command.

  • application_id (Optional[int]) – The ID of the application the command belongs to. This generally should be automatically filled in.

Raises

MissingApplicationID – The ID of the application was not found.

Returns

The partial message command.

Warning

Most of attributes will be fake, except for id, application_id, and guild_id.

Return type

MessageCommand

get_partial_slash_command(id, /, *, application_id=None)

Retrieve a very partial slash command that can be used to edit or delete the guild command.

Parameters
  • id (int) – The ID of the command.

  • application_id (Optional[int]) – The ID of the application the command belongs to. This generally should be automatically filled in.

Raises

MissingApplicationID – The ID of the application was not found.

Returns

The partial slash command.

Warning

Most of attributes will be fake, except for id, application_id, and guild_id.

Return type

SlashCommand

get_partial_user_command(id, /, *, application_id=None)

Retrieve a very partial user command that can be used to edit or delete the guild command.

Parameters
  • id (int) – The ID of the command.

  • application_id (Optional[int]) – The ID of the application the command belongs to. This generally should be automatically filled in.

Raises

MissingApplicationID – The ID of the application was not found.

Returns

The partial user command.

Warning

Most of attributes will be fake, except for id, application_id, and guild_id.

Return type

UserCommand

property icon

Returns the guild’s icon asset, if available.

Type

Optional[Asset]

await widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Raises
Returns

The guild’s widget.

Return type

Widget

Guild

class discord.rpc.Guild

Represents a Discord guild.

This inherits from PartialGuild.

vanity_url_code

The guild’s vanity URL code, if any.

Type

Optional[str]

await change_voice_state(*, channel, self_mute=False, self_deaf=False, self_video=False)

This function is a coroutine.

Changes client’s voice state in the guild.

New in version 1.4.

Parameters
  • channel (Optional[Snowflake]) – Channel the client wants to join. You must explicitly pass None to disconnect.

  • self_mute (bool) – Indicates if the client should be self-muted.

  • self_deaf (bool) – Indicates if the client should be self-deafened.

  • self_video (bool) – Indicates if the client should show camera.

await create_command(name, *, name_localizations=..., description=..., description_localizations=..., options=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=..., type=<AppCommandType.chat_input: 1>)

This function is a coroutine.

Creates an application command for the guild.

New in version 3.0.

Parameters
  • name (str) – The name for the slash command. Must be between 1 and 32 characters long.

  • name_localizations (Optional[Dict[Locale, str]]) –

    The name localizations for the slash command.

    Each value must be between 1 and 32 characters.

  • description (Optional[str]) – The description for the slash command. Can be only up to 100 characters.

  • description_localizations (Optional[Dict[Locale, str]]) –

    The description localizations for the slash command.

    Each value can be only up to 100 characters.

  • options (List[Union[Option, SlashCommandGroup]]) – The options for the slash command.

  • default_member_permissions (Optional[Permissions]) – The default permissions needed to use this application command. Pass value of None to remove any permission requirements.

  • dm_permission (bool) –

    Indicates if the application command can be used in DMs.

    Deprecated since version 3.0: Edit allowed_contexts instead.

  • allowed_contexts (Optional[AppCommandContext]) – The contexts that this command should be allowed to be used in. Overrides the dm_permission parameter.

  • allowed_installs (Optional[AppInstallationType]) – The installation contexts that this command should be allowed to be installed in.

  • type (AppCommandType) – The type for the application command. Defaults to chat_input.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The application command created.

Return type

Union[SlashCommand, UserCommand, MessageCommand]

await create_message_command(name, *, name_localizations=..., description=..., description_localizations=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=...)

This function is a coroutine.

Creates a message command for the guild.

The parameters are same as create_command() except options is removed.

New in version 3.0.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The message command created.

Return type

MessageCommand

await create_slash_command(name, *, name_localizations=..., description=..., description_localizations=..., options=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=...)

This function is a coroutine.

Creates a slash command for the guild.

The parameters are same as create_command().

New in version 3.0.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The slash command created.

Return type

SlashCommand

await create_user_command(name, *, name_localizations=..., description=..., description_localizations=..., default_member_permissions=..., dm_permission=..., allowed_contexts=..., allowed_installs=...)

This function is a coroutine.

Creates an user command for the guild.

The parameters are same as create_command() except options is removed.

New in version 3.0.

Raises
  • Forbidden – You do not have permission to create application command.

  • HTTPException – Creating the application command failed.

Returns

The user command created.

Return type

UserCommand

property created_at

Returns the guild’s creation time in UTC.

Type

datetime.datetime

await fetch_command(id, /)

This function is a coroutine.

Fetches an application command from the application.

Parameters

id (int) – The ID of the command to fetch.

Raises
  • HTTPException – Fetching the command failed.

  • MissingApplicationID – The application ID could not be found.

  • NotFound – The application command was not found. This could also be because the command is a global command.

Returns

The retrieved command.

Return type

Union[SlashCommand, UserCommand, MessageCommand, UnknownCommand]

await fetch_commands()

This function is a coroutine.

Fetches the application’s current commands.

Raises
Returns

The application’s commands.

Return type

List[Union[SlashCommand, UserCommand, MessageCommand, UnknownCommand]]

await fetch_me()

This function is a coroutine.

Retrieve member version of yourself for this guild.

Similar to Client.fetch_me() except returns Member. This is essentially used to get the member version of yourself.

Raises
  • Forbidden – You do not have proper permissions to fetch member version of yourself for this guild.

  • HTTPException – Retrieving member version of yourself failed.

Returns

The member version of yourself.

Return type

Member

get_partial_message_command(id, /, *, application_id=None)

Retrieve a very partial message command that can be used to edit or delete the guild command.

Parameters
  • id (int) – The ID of the command.

  • application_id (Optional[int]) – The ID of the application the command belongs to. This generally should be automatically filled in.

Raises

MissingApplicationID – The ID of the application was not found.

Returns

The partial message command.

Warning

Most of attributes will be fake, except for id, application_id, and guild_id.

Return type

MessageCommand

get_partial_slash_command(id, /, *, application_id=None)

Retrieve a very partial slash command that can be used to edit or delete the guild command.

Parameters
  • id (int) – The ID of the command.

  • application_id (Optional[int]) – The ID of the application the command belongs to. This generally should be automatically filled in.

Raises

MissingApplicationID – The ID of the application was not found.

Returns

The partial slash command.

Warning

Most of attributes will be fake, except for id, application_id, and guild_id.

Return type

SlashCommand

get_partial_user_command(id, /, *, application_id=None)

Retrieve a very partial user command that can be used to edit or delete the guild command.

Parameters
  • id (int) – The ID of the command.

  • application_id (Optional[int]) – The ID of the application the command belongs to. This generally should be automatically filled in.

Raises

MissingApplicationID – The ID of the application was not found.

Returns

The partial user command.

Warning

Most of attributes will be fake, except for id, application_id, and guild_id.

Return type

UserCommand

property icon

Returns the guild’s icon asset, if available.

Type

Optional[Asset]

await widget()

This function is a coroutine.

Returns the widget of the guild.

Note

The guild must have the widget enabled to get this information.

Raises
Returns

The guild’s widget.

Return type

Widget

Member

class discord.rpc.Member
property guild_avatar

Returns an Asset for the guild avatar the member has. If unavailable, None is returned.

Type

Optional[Asset]

property guild_avatar_decoration

Returns an Asset for the avatar decoration the member has.

If the member has not set an avatar decoration, None is returned.

Type

Optional[]

property guild_avatar_decoration_sku_id

Returns the SKU ID of the avatar decoration the member has.

If the member has not set an avatar decoration, None is returned.

Type

Optional[int]

property guild_banner

Returns an Asset for the guild banner the member has. If unavailable, None is returned.

Type

Optional[Asset]

Message

class discord.rpc.Message

Represents a message from Discord.

New in version 3.0.

x == y

Checks if two messages are equal.

x != y

Checks if two messages are not equal.

hash(x)

Returns the message’s hash.

id

The message ID.

Type

int

type

The type of message. In most cases this should not be checked, but it is helpful in cases where it might be a system message for system_content.

Type

MessageType

author

A User that sent the message.

Type

Optional[User]

blocked

Whether the message author is blocked.

Type

bool

bot

Whether the message author is bot.

Type

bool

content

The actual contents of the message.

Type

str

content_parsed

A list of message content components.

Type

List[dict]

attachments

A list of attachments given to a message.

Type

List[Attachment]

embeds

A list of embeds the message has.

Type

List[Embed]

tts

Specifies if the message was done with text-to-speech. This can only be accurately received in on_message() due to a Discord limitation.

Type

bool

edited_at

An aware UTC datetime object containing the edited time of the message.

Type

Optional[datetime]:

mentions

A list of users that were mentioned. For messages that are not of type MessageType.default, this array can be used to aid in system messages. For more information, see system_content.

Warning

The order of the mentions list is not in any particular order so you should not rely on it. This is a Discord limitation, not one with the library.

Type

List[Union[User, Object]]

mention_everyone

Specifies if the message mentions everyone.

Note

This does not check if the @everyone or the @here text is in the message itself. Rather this boolean indicates if either the @everyone or the @here text is in the message and it did end up mentioning.

Type

bool

role_mentions

A list of IDs of roles that were mentioned.

Type

List[int]

pinned

Specifies if the message is currently pinned.

Type

bool

author_color

The CSS color of the author.

Type

Optional[str]

nick

The rendered nick of the author.

Type

Optional[str]

Notification

Attributes
class discord.rpc.Notification

Represents a notification.

message

The message that triggered the notification.

Type

Message

icon_url

The icon URL.

Type

Optional[str]

title

The notification’s title.

Type

str

body

The notification’s body.

Type

str

QuestEnrollmentStatus

class discord.rpc.QuestEnrollmentStatus

Represents enrollment status for a quest.

quest_id

The quest’s ID the enrollment status is for.

Type

int

enrolled

Whether the user accepted the quest.

Type

bool

enrolled_at

When the user accepted the quest.

Type

Optional[datetime]

UserVoiceSettings

Attributes
class discord.rpc.UserVoiceSettings

Represents voice settings for a specific user.

New in version 3.0.

id

The target user’s ID these voice settings are set for.

Type

int

pan

The pan of the target user, set locally.

Type

Pan

volume

The volume of the target user, set locally.

Type

float

mute

Indicates whether the user muted target locally.

Type

bool

VoiceSettingsMode

class discord.rpc.VoiceSettingsMode

Represents the voice settings mode.

New in version 3.0.

type

The type of the voice settings mode.

Type

VoiceSettingsModeType

auto_threshold

Indicates if the voice activity threshold is automatically set.

Type

bool

threshold

The threshold for voice activity (in dB). Must between -100 and 0.

Type

int

shortcut

The shortcut key combos for PTT.

Type

List[ShortcutKeyCombo]

delay

The PTT release delay in milliseconds. Must be between 0 and 2000.

Type

int

VoiceSettings

class discord.rpc.VoiceSettings

Represents voice settings.

New in version 3.0.

input

The input settings.

Type

VoiceIOSettings

output

The output settings.

Type

VoiceIOSettings

mode

The voice mode settings.

Type

VoiceSettingsMode

automatic_gain_control

Indicates if automatic gain control is enabled.

Type

bool

echo_cancellation

Indicates if echo cancellation is enabled.

Type

bool

noise_suppression

Indicates if the background noise is being suppressed.

Type

bool

qos

Indicates if Voice Quality of Service (QoS) is enabled.

Type

bool

silence_warning

Indicates if the silence warning notice is disabled.

Type

bool

deaf

Indicates if the user is deafened by their accord.

Type

bool

mute

Indicates if the user is muted by their accord.

Type

bool

VoiceConnectionPing

Attributes
class discord.rpc.VoiceConnectionPing

Represents a ping to voice server.

at

When the ping was made.

Type

datetime

value

The latency in milliseconds.

Type

int

VoiceConnectionStatus

class discord.rpc.VoiceConnectionStatus

VoiceState

class discord.rpc.VoiceState

Represents a Discord user’s voice state.

Unlike discord.VoiceState, these are received from RPC.

New in version 3.0.

user

The user this voice state is for.

Type

discord.User

mute

Indicates if the user is currently muted by the guild.

Type

bool

deaf

Indicates if the user is currently deafened by the guild.

Type

bool

self_mute

Indicates if the user is currently muted by their own accord.

Type

bool

self_deaf

Indicates if the user is currently deafened by their own accord.

Type

bool

suppress

Indicates if the user is suppressed from speaking.

Only applies to stage channels.

Type

bool

nick

The nick of the user.

Type

str

local_mute

Indicates if the user is currently muted locally in the Discord client.

Type

bool

local_volume

The user’s volume, set locally.

Type

float

pan

The pan of user, set locally.

Type

Pan

Data Classes

Some classes are just there to be data containers, this lists them.

Unlike models you are allowed to create most of these yourself, even if they can also be used to hold attributes.

Nearly all classes here have __slots__ defined which means that it is impossible to have dynamic attributes to the data classes.

CertifiedDevice

class discord.rpc.CertifiedDevice(id, *, type, vendor_name, vendor_url, model_name, model_url, related=None, echo_cancellation=None, noise_suppression=None, automatic_gain_control=None, hardware_mute=None)

Represents a certified device.

type

The type of the certified device.

Type

CertifiedDeviceType

id

The certified device’s Windows UUID.

Type

str

vendor_name

The name of the hardware vendor.

Type

str

vendor_url

The URL to the hardware vendor.

Type

str

model_name

The name of the model.

Type

str

model_url

The URL to the model.

Type

str

related

A list of UUIDs representing related devices.

Type

Optional[List[str]]

echo_cancellation

Indicates if the device’s native echo cancellation is enabled.

Only applicable if type is audio_input.

Type

Optional[bool]

noise_suppression

Indicates if the device’s native noise suppression is enabled.

Only applicable if type is audio_input.

Type

Optional[bool]

automatic_gain_control

Indicates if the device’s automatic gain control is enabled.

Only applicable if type is audio_input.

Type

Optional[bool]

hardware_mute

Indicates if the device’s is muted hardware-wise.

Only applicable if type is audio_input.

Type

Optional[bool]

PreviewImage

Attributes
class discord.rpc.PreviewImage(url, *, height, width)

Represents a image preview.

height

The height of the image.

Type

int

url

The URL to the image.

Type

str

width

The width of the image.

Type

int

AvailableDevice

class discord.rpc.AvailableDevice(*, id, name)

VoiceIOSettings

class discord.rpc.VoiceIOSettings(*, available_devices=None, device_id, volume)

Represents I/O voice settings.

New in version 3.0.

available_devices

The available devices.

This is received only and setting will have no effect.

Type

List[AvailableDevice]

device_id

The ID of the primary device.

Type

str

volume

The input voice level. Must be between 0 and 100.

Type

float

ShortcutKeyCombo

Attributes
class discord.rpc.ShortcutKeyCombo(code, *, type, name=None)

Represents a shortcut key combo for PTT (Push-To-Talk).

type

The type of the combo.

Type

ShortcutKeyComboType

code

The code of the combo.

Type

int

name

The name of the combo.

Type

Optional[str]

PartialVoiceSettingsMode

class discord.rpc.PartialVoiceSettingsMode(*, type, auto_threshold=..., threshold=..., shortcut=..., delay=...)

Represents a modification of voice settings mode.

Unmodified fields will have their values set to MISSING (except for type).

New in version 3.0.

type

The new type of the voice settings mode.

Type

VoiceSettingsModeType

auto_threshold

Indicates if the voice activity threshold should be automatically set.

Type

bool

threshold

The new threshold for voice activity (in dB). Must between -100 and 0.

Type

int

shortcut

The shortcut key combos for PTT.

Type

List[ShortcutKeyCombo]

delay

The new PTT release delay in milliseconds. Must be between 0 and 2000.

Type

int

VoiceInputMode

Attributes
class discord.rpc.VoiceInputMode(shortcut, *, type)

Represents mode for the voice input.

type

The type.

Type

VoiceSettingsModeType

shortcut

The shortcut.

Type

VoiceSettingsModeType

EventSubscription

class discord.rpc.EventSubscription

Represents an event subscription.

New in version 3.0.

GenericSubscription

class discord.rpc.GenericSubscription(type)

Represents a subscription for a generic event (event that does not require arguments).

ChannelSubscription

class discord.rpc.ChannelSubscription(type, *, channel_id)

Represents a subscription for a channel event (event that happens in a specific channel).

GuildSubscription

class discord.rpc.GuildSubscription(type, *, guild_id)

Represents a subscription for a guild event (event that happens in a specific guild).

SpeakingEventSubscription

class discord.rpc.SpeakingEventSubscription(operation, *, channel_id, user_id)

Button

Attributes
class discord.rpc.Button(*, style=<ButtonStyle.secondary: 2>, label=None, custom_id=None)

Represents a button when sharing an interaction.

style

The button’s style.

Type

ButtonStyle

label

The label. Can be only up to 80 characters long.

Type

Optional[str]

custom_id

The developer-defined ID of the button. Can be only up to 100 characters long.

Type

Optional[str]

Pan

Attributes
class discord.rpc.Pan(*, left, right)

Represents a left and right pan for user.

New in version 3.0.

left

The left pan of user. Can be only between 0.0 and 1.0.

Type

float

right

The right pan of user. Can be only between 0.0 and 1.0.

Type

float

Exceptions

The following exceptions are thrown by the library.

exception discord.rpc.RPCException(*, code, text)

Exception that’s raised when a RPC request operation fails.

code

The Discord specific error code for the failure.

Type

int

text

The text of the error. Could be an empty string.

Type

str