From 6082eb21e3b8a7b55ad16055c16d3598a569cb58 Mon Sep 17 00:00:00 2001 From: Michael H Date: Sun, 12 Aug 2018 21:10:13 -0400 Subject: [PATCH] [V3] Enforce use of redbot.core.commands (#1971) * enforce commands as ours * clearer user feedback * No more 'one more tweak' commits without verifying anyway * more detailed error with docs link + docs update Resolves #1972. --- docs/framework_commands.rst | 5 +++-- redbot/core/bot.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/framework_commands.rst b/docs/framework_commands.rst index 89ef5a28d..d07a91b0a 100644 --- a/docs/framework_commands.rst +++ b/docs/framework_commands.rst @@ -5,8 +5,9 @@ Commands Package ================ This package acts almost identically to :doc:`discord.ext.commands `; i.e. -they both have the same attributes. Some of these attributes, however, have been slightly modified, -as outlined below. +all of the attributes from discord.py's are also in ours. +Some of these attributes, however, have been slightly modified, while others have been added to +extend functionlities used throughout the bot, as outlined below. .. autofunction:: redbot.core.commands.command diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 233f20acb..9bb343606 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -291,6 +291,22 @@ class RedBase(BotBase, RPCMixin): if pkg_name.startswith("redbot.cogs."): del sys.modules["redbot.cogs"].__dict__[name] + def add_cog(self, cog): + for attr in dir(cog): + _attr = getattr(cog, attr) + if isinstance(_attr, discord.ext.commands.Command) and not isinstance( + _attr, commands.Command + ): + raise RuntimeError( + f"The {cog.__class__.__name__} cog in the {cog.__module__} package," + " is not using Red's command module, and cannot be added. " + "If this is your cog, please use from `redbot.core import commands`" + "in place of `from discord.ext import commands`. For more details on " + "this requirement, see this page: " + "http://red-discordbot.readthedocs.io/en/v3-develop/framework_commands.html" + ) + super().add_cog(cog) + class Red(RedBase, discord.AutoShardedClient): """