fix: call set_my_commands in async context via setup_global_commands
This commit is contained in:
+8
-7
@@ -222,14 +222,15 @@ async def _refresh_kw_card(bot, chat_id: int, message_id: int, kw_id_full: str):
|
|||||||
|
|
||||||
# ── handler registration + global commands ────────────────────────────────
|
# ── handler registration + global commands ────────────────────────────────
|
||||||
|
|
||||||
def register_handlers(app: Application) -> None:
|
async def setup_global_commands(app: Application) -> None:
|
||||||
async def _setup_commands(application: Application) -> None:
|
"""Call this from main() after building the app to register bot commands."""
|
||||||
await application.bot.set_my_commands([
|
await app.bot.set_my_commands([
|
||||||
{"command": "start", "description": "Open main menu"},
|
{"command": "start", "description": "Open main menu"},
|
||||||
{"command": "admin", "description": "Admin panel (admins only)"},
|
{"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("start", start_handler))
|
||||||
app.add_handler(CommandHandler("admin", admin_handler))
|
app.add_handler(CommandHandler("admin", admin_handler))
|
||||||
app.add_handler(CallbackQueryHandler(callback_router))
|
app.add_handler(CallbackQueryHandler(callback_router))
|
||||||
|
|||||||
+2
-1
@@ -154,8 +154,9 @@ async def main() -> None:
|
|||||||
|
|
||||||
app = Application.builder().token(os.getenv("TELEGRAM_BOT_TOKEN")).build()
|
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)
|
register_handlers(app)
|
||||||
|
|
||||||
scheduler = asyncio.ensure_future(scheduler_task(pool, app.bot))
|
scheduler = asyncio.ensure_future(scheduler_task(pool, app.bot))
|
||||||
|
|||||||
Reference in New Issue
Block a user