Skip to content

DiscordError

Internal API

These classes are for internal use only.

Users should interact with Client and other public API classes instead.


DiscordError

Bases: Exception

Represents a Discord API error.

Initialize the error with Discord's response. Extracts reason, code, and walks the nested errors.

Parameters:

  • data (dict) –

    Discord's error JSON

data = data instance-attribute

Raw error data.

reason = data.get('message', 'Unknown Error') instance-attribute

Discord-generated reason for error.

code = data.get('code', '???') instance-attribute

Discord-generated code of error.

error_data = data.get('errors', {}) instance-attribute

Error-specific data.

details = self.walk(self.error_data) instance-attribute

Error details.

fatal = status in (401, 403) instance-attribute

If this error is considered fatal.

walk

Recursively traverses errors field to flatten nested validation errors into (path, message).

Parameters:

  • node (dict) –

    current error level

  • path (tuple[str, str], default: None ) –

    path to this error level

Returns:

  • list

    list of errors