Fix an issue with autocomplete in ignored channels/servers (#6375)

This commit is contained in:
TrustyJAID 2024-05-06 17:53:37 -06:00 committed by GitHub
parent e03f97d1cd
commit 4242a7adf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -334,6 +334,20 @@ class RedTree(CommandTree):
else: else:
log.exception(type(error).__name__, exc_info=error) log.exception(type(error).__name__, exc_info=error)
async def _send_interaction_check_failure(
self, interaction: discord.Interaction, message: str
):
"""Handles responding to interaction check failures.
Mainly used for when an interaction is an autocomplete and
providing the message in the autocomplete response.
"""
if interaction.type is discord.InteractionType.autocomplete:
await interaction.response.autocomplete(
[discord.app_commands.Choice(name=message[:80], value="None")]
)
return
await interaction.response.send_message(message, ephemeral=True)
async def interaction_check(self, interaction: discord.Interaction): async def interaction_check(self, interaction: discord.Interaction):
"""Global checks for app commands.""" """Global checks for app commands."""
if interaction.user.bot: if interaction.user.bot:
@ -341,15 +355,15 @@ class RedTree(CommandTree):
if interaction.guild: if interaction.guild:
if not (await self.client.ignored_channel_or_guild(interaction)): if not (await self.client.ignored_channel_or_guild(interaction)):
await interaction.response.send_message( await self._send_interaction_check_failure(
"This channel or server is ignored.", ephemeral=True interaction, _("This channel or server is ignored.")
) )
return False return False
if not (await self.client.allowed_by_whitelist_blacklist(interaction.user)): if not (await self.client.allowed_by_whitelist_blacklist(interaction.user)):
await interaction.response.send_message( await self._send_interaction_check_failure(
"You are not permitted to use commands because of an allowlist or blocklist.", interaction,
ephemeral=True, _("You are not permitted to use commands because of an allowlist or blocklist."),
) )
return False return False