Skip to content

Commit

Permalink
Fix an issue with autocomplete in ignored channels/servers (#6375)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrustyJAID committed May 6, 2024
1 parent e03f97d commit 4242a7a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions redbot/core/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,36 @@ async def on_error(
else:
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):
"""Global checks for app commands."""
if interaction.user.bot:
return False

if interaction.guild:
if not (await self.client.ignored_channel_or_guild(interaction)):
await interaction.response.send_message(
"This channel or server is ignored.", ephemeral=True
await self._send_interaction_check_failure(
interaction, _("This channel or server is ignored.")
)
return False

if not (await self.client.allowed_by_whitelist_blacklist(interaction.user)):
await interaction.response.send_message(
"You are not permitted to use commands because of an allowlist or blocklist.",
ephemeral=True,
await self._send_interaction_check_failure(
interaction,
_("You are not permitted to use commands because of an allowlist or blocklist."),
)
return False

Expand Down

0 comments on commit 4242a7a

Please sign in to comment.