[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.
This commit is contained in:
Michael H 2018-08-12 21:10:13 -04:00 committed by Toby Harradine
parent a91cda4995
commit 6082eb21e3
2 changed files with 19 additions and 2 deletions

View File

@ -5,8 +5,9 @@ Commands Package
================ ================
This package acts almost identically to :doc:`discord.ext.commands <dpy:ext/commands/api>`; i.e. This package acts almost identically to :doc:`discord.ext.commands <dpy:ext/commands/api>`; i.e.
they both have the same attributes. Some of these attributes, however, have been slightly modified, all of the attributes from discord.py's are also in ours.
as outlined below. 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 .. autofunction:: redbot.core.commands.command

View File

@ -291,6 +291,22 @@ class RedBase(BotBase, RPCMixin):
if pkg_name.startswith("redbot.cogs."): if pkg_name.startswith("redbot.cogs."):
del sys.modules["redbot.cogs"].__dict__[name] 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): class Red(RedBase, discord.AutoShardedClient):
""" """