From 922c7fe86aa580984584b8541e33b1a9a3962aca Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sun, 1 Mar 2026 17:51:56 +0100 Subject: [PATCH] Core: allow async def functions as commands (#5859) --- MultiServer.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MultiServer.py b/MultiServer.py index d317e7b8fa..ed50c98db6 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -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)