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¶
- asyncaccept_activity_invite
- asyncadd_subscription
- asyncauthenticate
- asyncauthorize
- asynccapture_log_entry
- asyncchange_presence
- defclear
- asyncclose
- asynccreate_channel_invite
- asynccreate_networking_token
- asyncdeep_link
- defdispatch
- asyncedit_embedded_activity_config
- asyncedit_orientation_lock_state
- asyncedit_user_voice_settings
- asyncedit_user_voice_settings_2
- asyncedit_voice_settings
- asyncedit_voice_settings_2
- asyncencourage_hardware_acceleration
- @event
- asyncfetch_activity_instance_participants
- asyncfetch_application_ticket
- asyncfetch_channel
- asyncfetch_current_channel_permissions
- asyncfetch_entitlement_ticket
- asyncfetch_entitlements
- asyncfetch_gift
- asyncfetch_guild
- asyncfetch_guild_channels
- asyncfetch_guilds
- asyncfetch_image
- asyncfetch_networking_config
- asyncfetch_platform_behaviors
- asyncfetch_provider_access_token
- asyncfetch_quest_enrollment_status
- asyncfetch_relationships
- asyncfetch_selected_voice_channel
- asyncfetch_skus
- asyncfetch_soundboard_sounds
- asyncfetch_template
- asyncfetch_user
- asyncfetch_user_locale
- asyncfetch_voice_settings
- asynchandoff
- asyncinitiate_image_upload
- asyncinvite_user_embedded
- defis_closed
- asyncmaybe_fetch_provider_access_token
- asyncnavigate_to_connections
- asyncon_error
- asyncopen_external_link
- asyncopen_invite_dialog
- asyncopen_invite_modal
- asyncopen_message
- asyncopen_overlay_activity_invite
- asyncopen_overlay_guild_invite
- asyncopen_overlay_voice_settings
- asyncopen_share_moment_dialog
- asyncoverlay
- asyncplay_soundboard_sound
- asyncpush_to_talk
- asyncreject_activity_join_request
- asyncremove_subscription
- asyncselect_text_channel
- asyncselect_voice_channel
- asyncsend_activity_invite
- asyncsend_activity_join_invite
- asyncsend_analytics_event
- asyncset_certified_devices
- asyncset_overlay_locked
- asyncsetup_hook
- asyncshare_interaction
- asyncshare_link
- asyncstart
- asyncstart_premium_purchase
- asyncstart_purchase
- asyncstart_quest_timer
- asyncsuppress_notifications
- asynctoggle_screenshare
- asynctoggle_video
- asynctrack_networking_peer_metrics
- asynctrack_networking_system_metrics
- asynctrigger_billing_popup_bridge_callback
- asynctrigger_braintree_popup_bridge_callback
- asynctrigger_connections_callback
- asyncupgrade
- asyncvalidate_application
- 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.- 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
- 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 theon_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()andwait_until_ready().
- await start(client_id, *, background=False, pipe=None, timeout=30.0)¶
This function is a coroutine.
Connects to the IPC socket.
- Parameters
- Returns
The task that handles the flow.
- Return type
Optional[
asyncio.Task]
- clear()¶
Clears the internal state of the client.
After this, the client can be considered “re-opened”, i.e.
is_closed()andis_ready()both returnFalsealong with the client’s internal cache cleared.
- property user¶
The currently connected user.
Noneif 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
- 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 tocode.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 usingcode_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 requestingopenidscope.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.incomingscope andinstall_typeisguild.channel (Optional[
Snowflake]) –The channel to pre-fill the dropdown picker with.
Only applicable if requesting
webhook.incomingscope.prompt (Optional[
PromptBehavior]) – The prompt behavior to use for the authorization flow. Defaults toconsent.disable_guild_select (Optional[
bool]) – Disallows the user from changing the guild dropdown. Only applicable when requestingbot/applications.commands/webhook.incomingscope andinstall_typeisguild. Defaults toFalse.install_type (Optional[
InstallationType]) – The installation context for the authorization. Only applicable when requestingapplication.commandsscope. Defaults toguild.pid (Optional[
int]) –The ID of the process to open the authorization modal in. If
Nonewasn’t explicitly passed, this defaults to result ofpid.If
Noneis 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
- 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
Guildwith 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
- 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
GuildChannelfrom 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
- 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
- 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.activitywill be notNoneif 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
- 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
- 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
rpcorrpc.voice.writeOAuth2 scope.All parameters are optional.
- Parameters
- Raises
RPCException – Editing the user voice settings failed.
- Returns
The newly updated user voice settings.
- Return type
- 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
- 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. PassNoneto 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 toFalse.navigate (Optional[
bool]) – Whether to navigate to the voice channel after joining. Defaults toFalse.
- 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
- 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
- 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
- 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. PassingNonedenotes 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
- 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
- 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.
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.
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 topid.
- Raises
RPCException – Sharing the interaction failed.
- Returns
Whether the interaction was shared successfully.
- Return type
- 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
This function is a coroutine.
Shares a link.
- Parameters
- Raises
RPCException – Sharing the link failed.
- Returns
The result of sharing link.
- Return type
- 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
- await deep_link(location, *, params=...)¶
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.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
- 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
- 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
- await open_message(channel_id, message_id, *, guild_id=..., pid=...)¶
This function is a coroutine.
Jumps to a message.
- Parameters
- 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
- 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
- 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
- Raises
RPCException – Retrieving the image failed.
- Returns
The data URL of the image.
- Return type
- await set_overlay_locked(value, *, pid=...)¶
This function is a coroutine.
Sets whether the overlay is locked.
- Parameters
- 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 topid.- Raises
RPCException – Opening failed.
- await open_overlay_guild_invite(code, *, pid=...)¶
This function is a coroutine.
Opens the guild invite in overlay.
- Parameters
- 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 topid.- 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
- 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
- await start_purchase(sku_id, *, pid=...)¶
This function is a coroutine.
Starts a SKU purchase flow.
- Parameters
- Raises
RPCException – Starting the SKU purchase flow failed.
- Returns
The entitlements.
- Return type
List[
Entitlement]
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_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
- 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
- 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
- await send_analytics_event(name, properties)¶
This function is a coroutine.
Send analytics event.
- Parameters
- Raises
RPCException – Sending the analytics event failed.
- await open_external_link(url)¶
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
- await capture_log_entry(message, *, level=<LogLevel.log: 'log'>)¶
This function is a coroutine.
Capture a log entry.
- Parameters
- 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
- await edit_orientation_lock_state(lock_state, *, pip_lock_state=..., grid_lock_state=...)¶
This function is a coroutine.
Edits the orientation lock state.
- Parameters
lock_state (
OrientationLockState) – The new lock state.pip_lock_state (Optional[
OrientationLockState]) – The new picture-in-picture lock state.grid_lock_state (Optional[
OrientationLockState]) – The new grid lock state.
- 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
- 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
- Raises
RPCException – Playing the soundboard sound failed.
- await toggle_video()¶
This function is a coroutine.
Toggles the video display.
- Raises
RPCException – Toggling disabled.
This function is a coroutine.
Toggles the screenshare display.
- Parameters
pid (Optional[
int]) – The ID of the process to screenshare. Defaults topid.- 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
- 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
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
- Raises
RPCException – Inviting the user failed.
- dispatch(event, /, *args, **kwargs)¶
Dispatch an event.
Examples
Dispatch an
mentionevent 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 withon_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,
TypeErroris raised.Example
@client.event async def on_ready(): print('Ready!')
Changed in version 2.0:
coroparameter 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
- 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_methodparameter is now positional-only and instead of writing tosys.stderrit 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
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
ClientUserupdates their profile.This is called when one or more of the following things change:
avatar
username
discriminator
- Parameters
before (Optional[
discord.ClientUser]) – The updated user’s old info.after (
discord.ClientUser) – The updated user’s updated info.
Guilds¶
- discord.rpc.on_guild_update(guild)¶
Called when a
PartialGuildupdates, for example:Changed name
Changed icon
- Parameters
guild (
PartialGuild) – The guild after being updated.
- discord.rpc.on_guild_join(guild)¶
Called when a
PartialGuildis either created by theClientor when theClientjoins 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.Relationshipis 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.
- 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¶
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
Messageis 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
Messagereceives 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.
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 withends_atset to the end of the current billing period.- Parameters
entitlement (
discord.Entitlement) – The entitlement that was deleted.
Video¶
Called whenever screenshare state changes.
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.
- 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.
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¶
- asyncblock
- asynccreate_dm
- defis_blocked
- defis_friend
- defis_game_friend
- defis_ignored
- defmentioned_in
- asyncremove_friend
- asyncremove_game_friend
- asyncsend
- asyncsend_friend_request
- asyncsend_game_friend_request
- asyncunblock
- class discord.rpc.ActivityParticipant¶
Represents an activity participant.
Same as
User, except with additionalnicknameattribute.- 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
Assetfor the avatar the user has.If the user has not uploaded a global avatar,
Noneis returned. If you want the avatar that a user has displayed, considerdisplay_avatar.- Type
Optional[
discord.Asset]
- property avatar_decoration¶
Returns an
Assetfor the avatar decoration the user has.If the user has not set an avatar decoration,
Noneis 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,
Noneis 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
Forbidden – Not allowed to block this user.
HTTPException – Blocking the user failed.
- 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
- 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.DMChannelwith 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
- property default_avatar¶
Returns the default avatar for a given user.
- Type
- 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
- 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
- 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 thecreate_dm()coroutine function.- Type
Optional[Union[
DMChannel,EphemeralDMChannel]]
- property game_relationship¶
Returns the
GameRelationshipwith this user if applicable,Noneotherwise.- Type
Optional[
GameRelationship]
- 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
- 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
- property public_flags¶
The publicly available flags the user has.
- property relationship¶
Returns the
Relationshipwith this user if applicable,Noneotherwise.- 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 toNone(the default), then theembedparameter must be provided.To upload a single file, the
fileparameter should be used with a singleFileobject. To upload multiple files, thefilesparameter should be used with alistofFileobjects. Specifying both parameters will lead to an exception.Changed in version 2.0: This function will now raise
TypeErrororValueErrorinstead ofInvalidArgument.- 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 inallowed_mentions. If no object is passed at all then the defaults given byallowed_mentionsare 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
fileslist is not of the appropriate size.TypeError – You specified both
fileandfiles.
- Returns
The message that was sent.
- Return type
- 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
Forbidden – Not allowed to unblock this user.
HTTPException – Unblocking the user failed.
- property voice¶
Returns the user’s current voice state.
- Type
Optional[
discord.VoiceState]
PartialChannel¶
GuildChannel¶
- class discord.rpc.GuildChannel¶
Represents a Discord guild channel.
This inherits from
PartialChannel.New in version 3.0.
- bitrate¶
The channel’s preferred audio bitrate in bits per second. Only applicable if the channel is vocal (voice or stage) channel.
- Type
- 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
- position¶
The position in the channel list. This is a number that starts at 0. e.g. the top channel is position 0.
- Type
- 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]
PlatformBehaviors¶
EmbeddedActivityConfig¶
PartialGuild¶
- asyncchange_voice_state
- asynccreate_command
- asynccreate_message_command
- asynccreate_slash_command
- asynccreate_user_command
- asyncfetch_command
- asyncfetch_commands
- asyncfetch_me
- defget_partial_message_command
- defget_partial_slash_command
- defget_partial_user_command
- asyncwidget
- 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:idname
- 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 passNoneto 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 ofNoneto remove any permission requirements.dm_permission (
bool) –Indicates if the application command can be used in DMs.
Deprecated since version 3.0: Edit
allowed_contextsinstead.allowed_contexts (Optional[
AppCommandContext]) – The contexts that this command should be allowed to be used in. Overrides thedm_permissionparameter.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 tochat_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()exceptoptionsis 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
- 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
- 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()exceptoptionsis 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
- property created_at¶
Returns the guild’s creation time in UTC.
- Type
- 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
HTTPException – Fetching the commands failed.
MissingApplicationID – The application ID could not be found.
- 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 returnsMember. 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
- 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
- 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, andguild_id.- Return type
- 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
- 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, andguild_id.- Return type
- 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
- 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, andguild_id.- Return type
- 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
Forbidden – The widget for this guild is disabled.
HTTPException – Retrieving the widget failed.
- Returns
The guild’s widget.
- Return type
Guild¶
- asyncchange_voice_state
- asynccreate_command
- asynccreate_message_command
- asynccreate_slash_command
- asynccreate_user_command
- asyncfetch_command
- asyncfetch_commands
- asyncfetch_me
- defget_partial_message_command
- defget_partial_slash_command
- defget_partial_user_command
- asyncwidget
- class discord.rpc.Guild¶
Represents a Discord guild.
This inherits from
PartialGuild.- 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 passNoneto 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 ofNoneto remove any permission requirements.dm_permission (
bool) –Indicates if the application command can be used in DMs.
Deprecated since version 3.0: Edit
allowed_contextsinstead.allowed_contexts (Optional[
AppCommandContext]) – The contexts that this command should be allowed to be used in. Overrides thedm_permissionparameter.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 tochat_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()exceptoptionsis 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
- 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
- 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()exceptoptionsis 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
- property created_at¶
Returns the guild’s creation time in UTC.
- Type
- 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
HTTPException – Fetching the commands failed.
MissingApplicationID – The application ID could not be found.
- 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 returnsMember. 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
- 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
- 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, andguild_id.- Return type
- 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
- 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, andguild_id.- Return type
- 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
- 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, andguild_id.- Return type
- 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
Forbidden – The widget for this guild is disabled.
HTTPException – Retrieving the widget failed.
- Returns
The guild’s widget.
- Return type
Member¶
- class discord.rpc.Member¶
- property guild_avatar¶
Returns an
Assetfor the guild avatar the member has. If unavailable,Noneis returned.- Type
Optional[
Asset]
- property guild_avatar_decoration¶
Returns an
Assetfor the avatar decoration the member has.If the member has not set an avatar decoration,
Noneis returned.- Type
Optional[
]
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.
- 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
- attachments¶
A list of attachments given to a message.
- Type
List[
Attachment]
- 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
- 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, seesystem_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.
- mention_everyone¶
Specifies if the message mentions everyone.
Note
This does not check if the
@everyoneor the@heretext is in the message itself. Rather this boolean indicates if either the@everyoneor the@heretext is in the message and it did end up mentioning.- Type
Notification¶
QuestEnrollmentStatus¶
UserVoiceSettings¶
- class discord.rpc.UserVoiceSettings¶
Represents voice settings for a specific user.
New in version 3.0.
VoiceSettingsMode¶
- class discord.rpc.VoiceSettingsMode¶
Represents the voice settings mode.
New in version 3.0.
- type¶
The type of the voice settings mode.
- shortcut¶
The shortcut key combos for PTT.
- Type
List[
ShortcutKeyCombo]
VoiceSettings¶
VoiceConnectionPing¶
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
- suppress¶
Indicates if the user is suppressed from speaking.
Only applies to stage channels.
- Type
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
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¶
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]
ShortcutKeyCombo¶
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 fortype).New in version 3.0.
- type¶
The new type of the voice settings mode.
- shortcut¶
The shortcut key combos for PTT.
- Type
List[
ShortcutKeyCombo]
VoiceInputMode¶
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)¶
Pan¶
Exceptions¶
The following exceptions are thrown by the library.