Browse Source

[commands] Raise TypeError instead of ClientException in some places

Certain decorators and functions expect coroutines and raise an
exception when this is not met. Change these to raise the appropriate
TypeError since they can't actually be handled by the user gracefully
anyway.
pull/2048/head
Rapptz 6 years ago
parent
commit
aeabd0761e
  1. 18
      discord/ext/commands/bot.py
  2. 18
      discord/ext/commands/core.py

18
discord/ext/commands/bot.py

@ -321,11 +321,11 @@ class BotBase(GroupMixin):
Raises Raises
------- -------
:exc:`.ClientException` TypeError
The coroutine is not actually a coroutine. The coroutine passed is not actually a coroutine.
""" """
if not asyncio.iscoroutinefunction(coro): if not asyncio.iscoroutinefunction(coro):
raise discord.ClientException('The pre-invoke hook must be a coroutine.') raise TypeError('The pre-invoke hook must be a coroutine.')
self._before_invoke = coro self._before_invoke = coro
return coro return coro
@ -354,11 +354,11 @@ class BotBase(GroupMixin):
Raises Raises
------- -------
:exc:`.ClientException` TypeError
The coroutine is not actually a coroutine. The coroutine passed is not actually a coroutine.
""" """
if not asyncio.iscoroutinefunction(coro): if not asyncio.iscoroutinefunction(coro):
raise discord.ClientException('The post-invoke hook must be a coroutine.') raise TypeError('The post-invoke hook must be a coroutine.')
self._after_invoke = coro self._after_invoke = coro
return coro return coro
@ -390,7 +390,7 @@ class BotBase(GroupMixin):
name = func.__name__ if name is None else name name = func.__name__ if name is None else name
if not asyncio.iscoroutinefunction(func): if not asyncio.iscoroutinefunction(func):
raise discord.ClientException('Listeners must be coroutines') raise TypeError('Listeners must be coroutines')
if name in self.extra_events: if name in self.extra_events:
self.extra_events[name].append(func) self.extra_events[name].append(func)
@ -443,7 +443,7 @@ class BotBase(GroupMixin):
Raises Raises
------- -------
:exc:`.ClientException` TypeError
The function being listened to is not a coroutine. The function being listened to is not a coroutine.
""" """
@ -720,7 +720,7 @@ class BotBase(GroupMixin):
def help_command(self, value): def help_command(self, value):
if value is not None: if value is not None:
if not isinstance(value, HelpCommand): if not isinstance(value, HelpCommand):
raise discord.ClientException('help_command must be a subclass of HelpCommand') raise TypeError('help_command must be a subclass of HelpCommand')
if self._help_command is not None: if self._help_command is not None:
self._help_command._remove_from_bot(self) self._help_command._remove_from_bot(self)
self._help_command = value self._help_command = value

18
discord/ext/commands/core.py

@ -728,12 +728,12 @@ class Command(_BaseCommand):
Raises Raises
------- -------
discord.ClientException TypeError
The coroutine is not actually a coroutine. The coroutine passed is not actually a coroutine.
""" """
if not asyncio.iscoroutinefunction(coro): if not asyncio.iscoroutinefunction(coro):
raise discord.ClientException('The error handler must be a coroutine.') raise TypeError('The error handler must be a coroutine.')
self.on_error = coro self.on_error = coro
return coro return coro
@ -756,11 +756,11 @@ class Command(_BaseCommand):
Raises Raises
------- -------
:exc:`.ClientException` TypeError
The coroutine is not actually a coroutine. The coroutine passed is not actually a coroutine.
""" """
if not asyncio.iscoroutinefunction(coro): if not asyncio.iscoroutinefunction(coro):
raise discord.ClientException('The pre-invoke hook must be a coroutine.') raise TypeError('The pre-invoke hook must be a coroutine.')
self._before_invoke = coro self._before_invoke = coro
return coro return coro
@ -783,11 +783,11 @@ class Command(_BaseCommand):
Raises Raises
------- -------
:exc:`.ClientException` TypeError
The coroutine is not actually a coroutine. The coroutine passed is not actually a coroutine.
""" """
if not asyncio.iscoroutinefunction(coro): if not asyncio.iscoroutinefunction(coro):
raise discord.ClientException('The post-invoke hook must be a coroutine.') raise TypeError('The post-invoke hook must be a coroutine.')
self._after_invoke = coro self._after_invoke = coro
return coro return coro

Loading…
Cancel
Save