Core: allow async def functions as commands (#5859)

This commit is contained in:
Fabian Dill
2026-03-01 17:51:56 +01:00
committed by GitHub
parent e49ba2ff6f
commit 922c7fe86a

View File

@@ -1302,6 +1302,13 @@ class CommandMeta(type):
commands.update(base.commands)
commands.update({command_name[5:]: method for command_name, method in attrs.items() if
command_name.startswith("_cmd_")})
for command_name, method in commands.items():
# wrap async def functions so they run on default asyncio loop
if inspect.iscoroutinefunction(method):
def _wrapper(self, *args, _method=method, **kwargs):
return async_start(_method(self, *args, **kwargs))
functools.update_wrapper(_wrapper, method)
commands[command_name] = _wrapper
return super(CommandMeta, cls).__new__(cls, name, bases, attrs)