diff --git a/docs/cog_guides/core.rst b/docs/cog_guides/core.rst index 28ccbe206..50681102b 100644 --- a/docs/cog_guides/core.rst +++ b/docs/cog_guides/core.rst @@ -1829,7 +1829,10 @@ Commands to add servers or channels to the ignore list. The ignore list will prevent the bot from responding to commands in the configured locations. -.. Note:: Owners and Admins override the ignore list. +.. Note:: + + - Category ignores are ignored by user-installed commands + - Owners and Admins override the ignore list. .. _core-command-ignore-channel: @@ -1850,7 +1853,10 @@ Ignore commands in the channel, thread, or category. Defaults to the current thread or channel. -.. Note:: Owners, Admins, and those with Manage Channel permissions override ignored channels. +.. Note:: + + - Category ignores are ignored by user-installed commands + - Owners and Admins override the ignore list. **Examples:** diff --git a/redbot/core/_global_checks.py b/redbot/core/_global_checks.py index c3994d554..9107240d8 100644 --- a/redbot/core/_global_checks.py +++ b/redbot/core/_global_checks.py @@ -5,4 +5,7 @@ from . import commands def init_global_checks(bot): @bot.check_once async def check_message_is_eligible_as_command(ctx: commands.Context) -> bool: + if ctx.interaction is not None: + # equivalent checks are performed by `RedTree.interaction_check` + return True return await ctx.bot.message_eligible_as_command(ctx.message) diff --git a/redbot/core/_settings_caches.py b/redbot/core/_settings_caches.py index 8fdc2a216..3c678b899 100644 --- a/redbot/core/_settings_caches.py +++ b/redbot/core/_settings_caches.py @@ -161,6 +161,8 @@ class IgnoreManager: 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 @@ class IgnoreManager: 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 61dc118ce..d274526fd 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -819,6 +819,9 @@ class Red( Whether or not the message is eligible to be treated as a command. """ + # NOTE: any changes to implementation here may need to be made + # in the `RedTree.interaction_check` as well + channel = message.channel guild = message.guild @@ -911,7 +914,18 @@ class Red( 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 diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 93cacdeb8..854b2e1ff 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -5789,7 +5789,9 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): The ignore list will prevent the bot from responding to commands in the configured locations. - Note: Owners and Admins override the ignore list. + Notes: + - Category ignores are ignored by user-installed commands + - Owners, Admins, and those with Manage Channel permissions override ignored channels. """ @ignore.command(name="list") @@ -5821,7 +5823,9 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic): Defaults to the current thread or channel. - Note: Owners, Admins, and those with Manage Channel permissions override ignored channels. + Notes: + - Category ignores are ignored by user-installed commands + - Owners, Admins, and those with Manage Channel permissions override ignored channels. **Examples:** - `[p]ignore channel #general` - Ignores commands in the #general channel.