From 0d48ea28aeb8a6290d2aeab202efa9c8d6e30fe3 Mon Sep 17 00:00:00 2001 From: Mikhail Kirillov Date: Wed, 9 Oct 2024 03:40:27 +0400 Subject: Add /set command; Add error_handler; --- main.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'main.py') diff --git a/main.py b/main.py index 7ca8b59..10c05a7 100644 --- a/main.py +++ b/main.py @@ -35,19 +35,32 @@ async def unknown(update: Update, context: ContextTypes.DEFAULT_TYPE): text=INVALID_COMMAND ) +async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> None: + logging.error("Exception:", exc_info=context.error) + + await context.bot.send_message( + chat_id=update.effective_chat.id, + text=context.error.message + ) if __name__ == "__main__": app = ApplicationBuilder().token( os.environ.get("TELEGRAM_TOKEN") ).persistence(Persistence).build() + # Meta commands app.add_handler(CommandHandler("about", commands.about)) + + # Movie commands + app.add_handler(CommandHandler("set", commands.set_users)) app.add_handler(CommandHandler("add", commands.add_users)) app.add_handler(CommandHandler("list", commands.list_users)) app.add_handler(CommandHandler("remove", commands.remove_users)) app.add_handler(CommandHandler("chooser", commands.chooser_user)) - app.add_handler(MessageHandler(filters.COMMAND, unknown)) + app.add_error_handler(error_handler) + app.run_polling() + -- cgit v1.2.3