DiscordException

Represents an exception raised by Discord, when it response with a not expected response code.

Depending on Discord's response code, the http client's behaviours differently.

CodeMeaningBehaviour
200OKreturn
201CREATEDreturn
204NO CONTENTreturn
304NOT MODIFIEDreturn
400BAD REQUESTraise
401UNAUTHORIZEDraise
403FORBIDDENraise
404NOT FOUNDraise
405METHOD NOT ALLOWEDraise
429TOO MANY REQUESTSrate limited
500SERVER ERROR\*retry
502GATEWAY UNAVAILABLE\*retry
5XXSERVER ERRORraise

\* For five times a request can fail with OsError or return 501 / 502 response code. If the request fails with these cases for the fifth try and the last one resulted 501 / 502 response code, then DiscordException will be raised.

Attributes

debug_options : None, set of str

Debug options of the http client.

received_data : object

Deserialized json response data if applicable.

response : ClientResponse

The http client response, what caused the error.

sent_data : object

Sent data.

_code : None, int

Cache of the .code property.

If the response data does not contains code, then this attribute is set to 0.

_debug_info : None, str

cache of the .debug_info property.

_errors : None, list of str

Cache of the errors property.

_message : None, str

Cache of the .message property.

_request_info : None, str

Cache of the .request_info property.

_retry_after : None, float

Cache pf the .retry_after property.

_status : None, int

Cache of the .status property.

__suppress_context__

Properties

code

Returns the Discord's internal exception code, if it is included in the response's data. If not, then returns 0.

Returns

error_code : int

debug_info

Returns debug info.

Only displayed within .messages when rich discord exceptions are enabled.

Returns

debug_info : str

errors

Returns the errors shipped with the exception.

Might return an empty list.

Returns

errors : list of str

message

Returns the error message of the discord exception.

Returns

message : str

messages

Returns a list of the errors. The 0th element of the list is always a header line, what contains the exception's name, the response's reason and it's status. If set, then also the Discord's internal error code and it's message as well.

Every other element at the list is optional. Those are extra errors included in the response's data.

Returns

messages : list of str

request_info

Returns additional request information about the exception.

Returns

request_info : str

retry_after

After how much seconds the request should be retried. Applicable for rate limit errors, so the ones with status 429.

Returns

retry_after : float

status

The exception's response's status.

Returns

status : int

Methods

__new__(response, received_data, sent_data, debug_options)

Creates a new discord exception.

ParameterTypeDescription
response

None | ClientResponse

The http client response, what caused the error.

received_data

object

Deserialized json response data if applicable.

sent_data

object

Sent data.

debug_options

None, set of str

Debug options of the http client.

_create_debug_info()

Creates debug info.

Returns

debug_info : str

_get_code()

Parses out the Discord's inner exception code from the response's data. Sets it to ._code and returns it as well.

Returns

error_code : int

_get_errors()

Creates the errors shipped with the exception.

Might return an empty list.

Returns

errors : list of str

_get_message()

Creates the error message of the discord exception.

Returns

message : str

_get_request_info()

Creates additional request information about the exception.

Returns

request_info : str

_get_retry_after()

Returns after how much seconds the request should be retried. Defaults to 0.0.

Returns

retry_after : float

_get_status()

Returns the response's status. Defaults to 0.

Returns

status : int

__format__(code)

Formats the discord exception in a format string.

The only provided option is no code, which returns a short-ish representation.

ParameterTypeDescription
code

str

The option on based the result will be formatted.

Returns

exception : str

Raises

ValueError

Unknown format code.

__repr__()

Returns the representation of the object.

__str__()

Returns the representation of the object.