From 576ab269e84b4be80fff3091e56bac42fa0aa552 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 27 Sep 2023 04:51:33 -0400 Subject: [PATCH] Fix AttributeError in CommandSyncFailure due to APPLICATION_COMMAND_TOO_LARGE --- discord/app_commands/errors.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/discord/app_commands/errors.py b/discord/app_commands/errors.py index 3cc12c72d8cb..42de35e4e865 100644 --- a/discord/app_commands/errors.py +++ b/discord/app_commands/errors.py @@ -530,8 +530,18 @@ def __init__(self, child: HTTPException, commands: List[CommandTypes]) -> None: messages = [f'Failed to upload commands to Discord (HTTP status {self.status}, error code {self.code})'] if self._errors: - for index, inner in self._errors.items(): - _get_command_error(index, inner, commands, messages) + # Handle case where the errors dict has no actual chain such as APPLICATION_COMMAND_TOO_LARGE + if len(self._errors) == 1 and '_errors' in self._errors: + errors = self._errors['_errors'] + if len(errors) == 1: + extra = errors[0].get('message') + if extra: + messages[0] += f': {extra}' + else: + messages.extend(f'Error {e.get("code", "")}: {e.get("message", "")}' for e in errors) + else: + for index, inner in self._errors.items(): + _get_command_error(index, inner, commands, messages) # Equivalent to super().__init__(...) but skips other constructors self.args = ('\n'.join(messages),)