diff --git a/discord/client.py b/discord/client.py index 88c390be0946..b30e3b3a6e02 100644 --- a/discord/client.py +++ b/discord/client.py @@ -26,6 +26,7 @@ import asyncio import datetime +import inspect import logging from typing import ( TYPE_CHECKING, @@ -2052,7 +2053,7 @@ async def on_ready(): The coroutine passed is not actually a coroutine. """ - if not asyncio.iscoroutinefunction(coro): + if not inspect.iscoroutinefunction(coro): raise TypeError('event registered must be a coroutine function') setattr(self, coro.__name__, coro) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 0bb4cf95f5ed..ae050965cb0a 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -581,7 +581,7 @@ def before_invoke(self, coro: CFT, /) -> CFT: TypeError The coroutine passed is not actually a coroutine. """ - if not asyncio.iscoroutinefunction(coro): + if not inspect.iscoroutinefunction(coro): raise TypeError('The pre-invoke hook must be a coroutine.') self._before_invoke = coro @@ -618,7 +618,7 @@ def after_invoke(self, coro: CFT, /) -> CFT: TypeError The coroutine passed is not actually a coroutine. """ - if not asyncio.iscoroutinefunction(coro): + if not inspect.iscoroutinefunction(coro): raise TypeError('The post-invoke hook must be a coroutine.') self._after_invoke = coro @@ -654,7 +654,7 @@ async def my_message(message): pass """ name = func.__name__ if name is MISSING else name - if not asyncio.iscoroutinefunction(func): + if not inspect.iscoroutinefunction(func): raise TypeError('Listeners must be coroutines') if name in self.extra_events: diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 949539b61176..dbf2a69a9953 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -427,7 +427,7 @@ def __init__( /, **kwargs: Unpack[_CommandKwargs], ) -> None: - if not asyncio.iscoroutinefunction(func): + if not inspect.iscoroutinefunction(func): raise TypeError('Callback must be a coroutine.') name = kwargs.get('name') or func.__name__ @@ -1102,7 +1102,7 @@ def error(self, coro: Error[CogT, ContextT], /) -> Error[CogT, ContextT]: The coroutine passed is not actually a coroutine. """ - if not asyncio.iscoroutinefunction(coro): + if not inspect.iscoroutinefunction(coro): raise TypeError('The error handler must be a coroutine.') self.on_error: Error[CogT, Any] = coro @@ -1140,7 +1140,7 @@ def before_invoke(self, coro: Hook[CogT, ContextT], /) -> Hook[CogT, ContextT]: TypeError The coroutine passed is not actually a coroutine. """ - if not asyncio.iscoroutinefunction(coro): + if not inspect.iscoroutinefunction(coro): raise TypeError('The pre-invoke hook must be a coroutine.') self._before_invoke = coro @@ -1171,7 +1171,7 @@ def after_invoke(self, coro: Hook[CogT, ContextT], /) -> Hook[CogT, ContextT]: TypeError The coroutine passed is not actually a coroutine. """ - if not asyncio.iscoroutinefunction(coro): + if not inspect.iscoroutinefunction(coro): raise TypeError('The post-invoke hook must be a coroutine.') self._after_invoke = coro