Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Cog): raise error if InteractionBot has prefix commands related things #1018

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1018.bugfix.rst
@@ -0,0 +1 @@
|commands| Raise ``TypeError`` if :class:`~.ext.commands.InteractionBot` or :class:`~.ext.commands.AutoShardedInteractionBot` has prefix commands related things in a :class:`~.ext.commands.Cog`
18 changes: 16 additions & 2 deletions disnake/ext/commands/cog.py
Expand Up @@ -723,8 +723,16 @@ async def cog_after_message_command_invoke(self, inter: ApplicationCommandIntera
pass

def _inject(self, bot: AnyBot) -> Self:
from .bot import AutoShardedInteractionBot, InteractionBot

cls = self.__class__

if (
isinstance(bot, (InteractionBot, AutoShardedInteractionBot))
and len(self.__cog_commands__) > 0
):
raise TypeError("@commands.command is not supported for interaction bots.")

# realistically, the only thing that can cause loading errors
# is essentially just the command loading, which raises if there are
# duplicates. When this condition is met, we want to undo all what
Expand Down Expand Up @@ -766,10 +774,16 @@ def _inject(self, bot: AnyBot) -> Self:

# check if we're overriding the default
if cls.bot_check is not Cog.bot_check:
bot.add_check(self.bot_check) # type: ignore
if isinstance(bot, (InteractionBot, AutoShardedInteractionBot)):
raise TypeError("Cog.bot_check is not supported for interaction bots.")

bot.add_check(self.bot_check)

if cls.bot_check_once is not Cog.bot_check_once:
bot.add_check(self.bot_check_once, call_once=True) # type: ignore
if isinstance(bot, (InteractionBot, AutoShardedInteractionBot)):
raise TypeError("Cog.bot_check_once is not supported for interaction bots.")

bot.add_check(self.bot_check_once, call_once=True)

# Add application command checks
if cls.bot_slash_command_check is not Cog.bot_slash_command_check:
Expand Down