Exceptions#

Exception Hierarchy#

Objects#

The following exceptions are thrown by the library.

exception discord.DiscordException[source]#

Base exception class for pycord

Ideally speaking, this could be caught to handle any exceptions raised from this library.

exception discord.ClientException[source]#

Exception that’s raised when an operation in the Client fails.

These are usually for exceptions that happened due to user input.

exception discord.LoginFailure[source]#

Exception that’s raised when the Client.login() function fails to log you in from improper credentials or some other misc. failure.

exception discord.NoMoreItems[source]#

Exception that is raised when an async iteration operation has no more items.

exception discord.HTTPException(response, message)[source]#

Exception that’s raised when an HTTP request operation fails.

response#

The response of the failed HTTP request. This is an instance of aiohttp.ClientResponse. In some cases this could also be a requests.Response.

Type:

aiohttp.ClientResponse

text#

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

Type:

str

status#

The status code of the HTTP request.

Type:

int

code#

The Discord specific error code for the failure.

Type:

int

exception discord.Forbidden(response, message)[source]#

Exception that’s raised for when status code 403 occurs.

Subclass of HTTPException

exception discord.NotFound(response, message)[source]#

Exception that’s raised for when status code 404 occurs.

Subclass of HTTPException

exception discord.DiscordServerError(response, message)[source]#

Exception that’s raised for when a 500 range status code occurs.

Subclass of HTTPException.

New in version 1.5.

exception discord.InvalidData[source]#

Exception that’s raised when the library encounters unknown or invalid data from Discord.

exception discord.InvalidArgument[source]#

Exception that’s raised when an argument to a function is invalid some way (e.g. wrong value or wrong type).

This could be considered the parallel of ValueError and TypeError except inherited from ClientException and thus DiscordException.

exception discord.GatewayNotFound[source]#

An exception that is raised when the gateway for Discord could not be found

exception discord.ConnectionClosed(socket, *, shard_id, code=None)[source]#

Exception that’s raised when the gateway connection is closed for reasons that could not be handled internally.

code#

The close code of the websocket.

Type:

int

reason#

The reason provided for the closure.

Type:

str

shard_id#

The shard ID that got closed if applicable.

Type:

Optional[int]

Parameters:
  • socket (ClientWebSocketResponse) –

  • shard_id (int | None) –

  • code (int | None) –

exception discord.PrivilegedIntentsRequired(shard_id)[source]#

Exception that’s raised when the gateway is requesting privileged intents, but they’re not ticked in the developer page yet.

Go to https://discord.com/developers/applications/ and enable the intents that are required. Currently, these are as follows:

shard_id#

The shard ID that got closed if applicable.

Type:

Optional[int]

Parameters:

shard_id (int | None) –

exception discord.InteractionResponded(interaction)[source]#

Exception that’s raised when sending another interaction response using InteractionResponse when one has already been done before.

An interaction can only respond once.

New in version 2.0.

interaction#

The interaction that’s already been responded to.

Type:

Interaction

Parameters:

interaction (Interaction) –

exception discord.opus.OpusError(code)[source]#

An exception that is thrown for libopus related errors.

code#

The error code returned.

Type:

int

Parameters:

code (int) –

exception discord.opus.OpusNotLoaded[source]#

An exception that is thrown for when libopus is not loaded.

exception discord.ApplicationCommandError[source]#

The base exception type for all application command related errors.

This inherits from DiscordException.

This exception and exceptions inherited from it are handled in a special way as they are caught and passed into a special event from Bot, on_command_error().

exception discord.CheckFailure[source]#

Exception raised when the predicates in Command.checks have failed.

This inherits from ApplicationCommandError

exception discord.ApplicationCommandInvokeError(e)[source]#

Exception raised when the command being invoked raised an exception.

This inherits from ApplicationCommandError

original#

The original exception that was raised. You can also get this via the __cause__ attribute.

Type:

Exception

Parameters:

e (Exception) –

exception discord.ExtensionError(message=None, *args, name)[source]#

Base exception for extension related errors.

This inherits from DiscordException.

name#

The extension that had an error.

Type:

str

Parameters:
  • message (str | None) –

  • args (Any) –

  • name (str) –

exception discord.ExtensionAlreadyLoaded(name)[source]#

An exception raised when an extension has already been loaded.

This inherits from ExtensionError

Parameters:

name (str) –

exception discord.ExtensionNotLoaded(name)[source]#

An exception raised when an extension was not loaded.

This inherits from ExtensionError

Parameters:

name (str) –

exception discord.NoEntryPointError(name)[source]#

An exception raised when an extension does not have a setup entry point function.

This inherits from ExtensionError

Parameters:

name (str) –

exception discord.ExtensionFailed(name, original)[source]#

An exception raised when an extension failed to load during execution of the module or setup entry point.

This inherits from ExtensionError

name#

The extension that had the error.

Type:

str

original#

The original exception that was raised. You can also get this via the __cause__ attribute.

Type:

Exception

Parameters:
exception discord.ExtensionNotFound(name)[source]#

An exception raised when an extension is not found.

This inherits from ExtensionError

Changed in version 1.3: Made the original attribute always None.

name#

The extension that had the error.

Type:

str

Parameters:

name (str) –

exception discord.sinks.SinkException[source]#

Raised when a Sink error occurs.

New in version 2.0.

exception discord.sinks.RecordingException[source]#

Exception that’s thrown when there is an error while trying to record audio from a voice channel.

New in version 2.0.

exception discord.sinks.WaveSinkError[source]#

Exception thrown when an exception occurs with WaveSink

New in version 2.0.

exception discord.sinks.MP3SinkError[source]#

Exception thrown when an exception occurs with MP3Sink

New in version 2.0.

exception discord.sinks.MP4SinkError[source]#

Exception thrown when an exception occurs with MP4Sink

New in version 2.0.

exception discord.sinks.M4ASinkError[source]#

Exception thrown when an exception occurs with M4ASink

New in version 2.0.

exception discord.sinks.MKVSinkError[source]#

Exception thrown when an exception occurs with MKVSink

New in version 2.0.

exception discord.sinks.MKASinkError[source]#

Exception thrown when an exception occurs with MKASink

New in version 2.0.

exception discord.sinks.OGGSinkError[source]#

Exception thrown when an exception occurs with OGGSink

New in version 2.0.