diff options
| author | Rapptz <[email protected]> | 2021-01-15 06:00:28 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-01-15 06:00:45 -0500 |
| commit | b9a99238e8bd976be825f725fd57012268790c66 (patch) | |
| tree | c0ae6920a74b7ac1570ee397ab6c9733692d1b27 | |
| parent | Strip both - and _ from newcog class names (diff) | |
| download | discord.py-b9a99238e8bd976be825f725fd57012268790c66.tar.xz discord.py-b9a99238e8bd976be825f725fd57012268790c66.zip | |
[commands] Add Command/Cog.has_error_handler
This allows querying the state without relying on internal undocumented
attributes.
| -rw-r--r-- | discord/ext/commands/cog.py | 7 | ||||
| -rw-r--r-- | discord/ext/commands/core.py | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/discord/ext/commands/cog.py b/discord/ext/commands/cog.py index bea69c04..57c78b4e 100644 --- a/discord/ext/commands/cog.py +++ b/discord/ext/commands/cog.py @@ -296,6 +296,13 @@ class Cog(metaclass=CogMeta): return func return decorator + def has_error_handler(self): + """:class:`bool`: Checks whether the cog has an error handler. + + .. versionadded:: 1.7 + """ + return hasattr(self.cog_command_error.__func__, '__cog_special_method__') + @_cog_special_method def cog_unload(self): """A special method that is called when the cog gets removed. diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index b62eadb5..b17f878c 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -904,6 +904,13 @@ class Command(_BaseCommand): self.on_error = coro return coro + def has_error_handler(self): + """:class:`bool`: Checks whether the command has an error handler registered. + + .. versionadded:: 1.7 + """ + return hasattr(self, 'on_error') + def before_invoke(self, coro): """A decorator that registers a coroutine as a pre-invoke hook. |