Exceptions

The following exceptions are thrown by the library.

exception discord.DiscordException

Bases: Exception

Base exception class for discord.py

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

exception discord.ClientException

Bases: DiscordException

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

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

exception discord.LoginFailure

Bases: ClientException

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

exception discord.NoMoreItems

Bases: DiscordException

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

exception discord.HTTPException(response, message)

Bases: DiscordException

Exception that’s thrown 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.Unauthorized(response, message)

Bases: HTTPException

Exception that’s thrown for when status code 401 occurs.

Subclass of HTTPException

Added in version 2.0.

exception discord.Forbidden(response, message)

Bases: HTTPException

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

Subclass of HTTPException

exception discord.NotFound(response, message)

Bases: HTTPException

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

Subclass of HTTPException

exception discord.DiscordServerError(response, message)

Bases: HTTPException

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

Subclass of HTTPException.

Added in version 1.5.

exception discord.InvalidData

Bases: ClientException

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

exception discord.InvalidArgument

Bases: ClientException

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

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

exception discord.GatewayNotFound

Bases: DiscordException

An exception that is usually thrown when the gateway hub for the Client websocket is not found.

exception discord.ConnectionClosed(socket, *, shard_id, code=None)

Bases: ClientException

Exception that’s thrown 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]

exception discord.PrivilegedIntentsRequired(shard_id)

Bases: ClientException

Exception that’s thrown 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]

exception discord.AlreadyResponded(interaction_id)

Bases: DiscordException

Exception thrown when attempting to send the callback for an interaction that has already been responded to.’

exception discord.opus.OpusError(code)

Bases: DiscordException

An exception that is thrown for libopus related errors.

code

The error code returned.

Type:

int

exception discord.opus.OpusNotLoaded

Bases: DiscordException

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

exception discord.DiscordWarning

Bases: Warning

Base warning class for discord.py

Ideally speaking, this could be caught to handle any warnings thrown from this library.

Note

This inherits from Warning instead of Exception.

exception discord.UnknownInteraction(interaction_id)

Bases: DiscordWarning

A warning that comes when you try to interact with an expired interaction.

Exception Hierarchy