From b1e86319aca8311704dfaf6f7cd7586ac7c95302 Mon Sep 17 00:00:00 2001 From: Kowlin Date: Mon, 6 Jan 2025 03:43:00 +0100 Subject: [PATCH] Handle UIB interactions for ignoring channels. --- redbot/core/_settings_caches.py | 6 +++++- redbot/core/bot.py | 13 ++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/redbot/core/_settings_caches.py b/redbot/core/_settings_caches.py index 8fdc2a2165d..3c678b8994d 100644 --- a/redbot/core/_settings_caches.py +++ b/redbot/core/_settings_caches.py @@ -161,6 +161,8 @@ async def get_ignored_channel( discord.StageChannel, discord.ForumChannel, discord.Thread, + discord.Object, # This is solely here for the purpose of User Installed Bots, + # See Red#6501 & ignored_channel_or_guild in redbot/core/bot.py for more details. ], check_category: bool = True, ) -> bool: @@ -168,7 +170,9 @@ async def get_ignored_channel( cid: int = channel.id cat_id: Optional[int] = ( - channel.category.id if check_category and channel.category else None + channel.category.id + if check_category and hasattr(channel, "category") and channel.category is not None + else None ) if cid in self._cached_channels: chan_ret = self._cached_channels[cid] diff --git a/redbot/core/bot.py b/redbot/core/bot.py index c63b2bb9584..1e004b1e0c4 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -911,7 +911,18 @@ async def ignored_channel_or_guild( return True if isinstance(ctx.channel, discord.Thread): - channel = ctx.channel.parent + if isinstance(ctx, discord.Interaction) and ctx.is_user_integration(): + ctx: discord.Interaction + # This is a user installed interaction, and thus... We're doomed! + # We must mock an object because we don't have the channel cached, + # and we are unable to fetch a full channel from the interaction + # #BlameDiscord, See Red#6501 for more details. + + # LIMITATIONS: Due the fact that we don't know the categories either as they aren't... + # communicated in the interaction, we can't check for category ignores. + channel = discord.Object(id=ctx.channel.parent_id) + else: + channel = ctx.channel.parent thread = ctx.channel else: channel = ctx.channel