From 4e09c34bbbd034307dbad2713780de60934fe15a Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 17 Feb 2023 13:24:59 -0500 Subject: [PATCH] Suppress exceptions from invoking autocomplete --- discord/app_commands/commands.py | 8 ++++---- discord/app_commands/tree.py | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/discord/app_commands/commands.py b/discord/app_commands/commands.py index a164b34ea..fd6388443 100644 --- a/discord/app_commands/commands.py +++ b/discord/app_commands/commands.py @@ -887,11 +887,11 @@ class Command(Generic[GroupT, P, T]): predicates = getattr(param.autocomplete, '__discord_app_commands_checks__', []) if predicates: try: - if not await async_all(f(interaction) for f in predicates): - if not interaction.response.is_done(): - await interaction.response.autocomplete([]) - return + passed = await async_all(f(interaction) for f in predicates) except Exception: + passed = False + + if not passed: if not interaction.response.is_done(): await interaction.response.autocomplete([]) return diff --git a/discord/app_commands/tree.py b/discord/app_commands/tree.py index 16dcf3244..5bdfbec58 100644 --- a/discord/app_commands/tree.py +++ b/discord/app_commands/tree.py @@ -1235,7 +1235,13 @@ class CommandTree(Generic[ClientT]): focused = next((opt['name'] for opt in options if opt.get('focused')), None) if focused is None: raise AppCommandError('This should not happen, but there is no focused element. This is a Discord bug.') - await command._invoke_autocomplete(interaction, focused, namespace) + + try: + await command._invoke_autocomplete(interaction, focused, namespace) + except Exception: + # Suppress exception since it can't be handled anyway. + pass + return try: