From 709e0a65edf63b459b4f63c0734a0bf11be8855b Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Wed, 17 Jun 2026 11:53:06 +0200 Subject: [PATCH] fix: call set_my_commands in async context via setup_global_commands --- worker/src/bot.py | 15 ++++++++------- worker/src/main.py | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/worker/src/bot.py b/worker/src/bot.py index b829b06..a7fe794 100644 --- a/worker/src/bot.py +++ b/worker/src/bot.py @@ -222,14 +222,15 @@ async def _refresh_kw_card(bot, chat_id: int, message_id: int, kw_id_full: str): # ── handler registration + global commands ──────────────────────────────── -def register_handlers(app: Application) -> None: - async def _setup_commands(application: Application) -> None: - await application.bot.set_my_commands([ - {"command": "start", "description": "Open main menu"}, - {"command": "admin", "description": "Admin panel (admins only)"}, - ]) +async def setup_global_commands(app: Application) -> None: + """Call this from main() after building the app to register bot commands.""" + await app.bot.set_my_commands([ + {"command": "start", "description": "Open main menu"}, + {"command": "admin", "description": "Admin panel (admins only)"}, + ]) - app.post_init(_setup_commands) + +def register_handlers(app: Application) -> None: app.add_handler(CommandHandler("start", start_handler)) app.add_handler(CommandHandler("admin", admin_handler)) app.add_handler(CallbackQueryHandler(callback_router)) diff --git a/worker/src/main.py b/worker/src/main.py index 06a8202..7de4c60 100644 --- a/worker/src/main.py +++ b/worker/src/main.py @@ -154,8 +154,9 @@ async def main() -> None: app = Application.builder().token(os.getenv("TELEGRAM_BOT_TOKEN")).build() - from bot import register_handlers # noqa: E402 + from bot import register_handlers, setup_global_commands # noqa: E402 + await setup_global_commands(app) register_handlers(app) scheduler = asyncio.ensure_future(scheduler_task(pool, app.bot))