Exceptions

Exception Hierarchy

Objects

The following exceptions are thrown by the library.

exception discord.DiscordException[исходный код]

Base exception class for pycord

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

exception discord.ClientException[исходный код]

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[исходный код]

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[исходный код]

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

exception discord.HTTPException(response, message)[исходный код]

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)[исходный код]

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

Subclass of HTTPException

Параметры:
exception discord.NotFound(response, message)[исходный код]

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

Subclass of HTTPException

Параметры:
exception discord.DiscordServerError(response, message)[исходный код]

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

Subclass of HTTPException.

Добавлено в версии 1.5.

Параметры:
exception discord.InvalidData[исходный код]

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

exception discord.InvalidArgument[исходный код]

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[исходный код]

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

exception discord.ConnectionClosed(socket, *, shard_id, code=None)[исходный код]

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]

Параметры:
exception discord.PrivilegedIntentsRequired(shard_id)[исходный код]

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]

Параметры:

shard_id (int | None)

exception discord.InteractionResponded(interaction)[исходный код]

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

An interaction can only respond once.

Добавлено в версии 2.0.

interaction

The interaction that’s already been responded to.

Type:

Interaction

Параметры:

interaction (Interaction)

exception discord.opus.OpusError(code=0, message=None)[исходный код]

An exception that is thrown for libopus related errors.

code

The error code returned.

Type:

int

Параметры:
exception discord.opus.OpusNotLoaded[исходный код]

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

exception discord.ApplicationCommandError[исходный код]

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[исходный код]

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

This inherits from ApplicationCommandError

exception discord.ApplicationCommandInvokeError(e)[исходный код]

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

Параметры:

e (Exception)

exception discord.ExtensionError(message=None, *args, name)[исходный код]

Base exception for extension related errors.

This inherits from DiscordException.

name

The extension that had an error.

Type:

str

Параметры:
exception discord.ExtensionAlreadyLoaded(name)[исходный код]

An exception raised when an extension has already been loaded.

This inherits from ExtensionError

Параметры:

name (str)

exception discord.ExtensionNotLoaded(name)[исходный код]

An exception raised when an extension was not loaded.

This inherits from ExtensionError

Параметры:

name (str)

exception discord.NoEntryPointError(name)[исходный код]

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

This inherits from ExtensionError

Параметры:

name (str)

exception discord.ExtensionFailed(name, original)[исходный код]

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

Параметры:
exception discord.ExtensionNotFound(name)[исходный код]

An exception raised when an extension is not found.

This inherits from ExtensionError

Изменено в версии 1.3: Made the original attribute always None.

name

The extension that had the error.

Type:

str

Параметры:

name (str)

exception discord.sinks.SinkException[исходный код]

Raised when a Sink error occurs.

Добавлено в версии 2.0.

exception discord.sinks.RecordingException[исходный код]

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

Добавлено в версии 2.0.

exception discord.sinks.WaveSinkError[исходный код]

Exception thrown when an exception occurs with WaveSink

Добавлено в версии 2.0.

exception discord.sinks.MP3SinkError[исходный код]

Exception thrown when an exception occurs with MP3Sink

Добавлено в версии 2.0.

exception discord.sinks.MP4SinkError[исходный код]

Exception thrown when an exception occurs with MP4Sink

Добавлено в версии 2.0.

exception discord.sinks.M4ASinkError[исходный код]

Exception thrown when an exception occurs with M4ASink

Добавлено в версии 2.0.

exception discord.sinks.MKVSinkError[исходный код]

Exception thrown when an exception occurs with MKVSink

Добавлено в версии 2.0.

exception discord.sinks.MKASinkError[исходный код]

Exception thrown when an exception occurs with MKASink

Добавлено в версии 2.0.

exception discord.sinks.OGGSinkError[исходный код]

Exception thrown when an exception occurs with OGGSink

Добавлено в версии 2.0.

exception discord.MissingVoiceDependenciesError(missing)[исходный код]

Raised when required voice dependencies are not installed.

Примечание

This exception inherits from both RuntimeError and DiscordException.

missing

tuple[str, …] The missing dependencies that are required for voice support.

Параметры:

missing (tuple[str, ...])