From a5b42ac289db595eecd172588f0390aa9af7decc Mon Sep 17 00:00:00 2001 From: ngfchl Date: Tue, 7 Jul 2026 09:38:58 +0800 Subject: [PATCH] fix: make bind private chat link reliable --- handlers/bind.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/handlers/bind.py b/handlers/bind.py index e049278..c9b7391 100644 --- a/handlers/bind.py +++ b/handlers/bind.py @@ -17,6 +17,7 @@ EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$") async def cmd_bind(update: Update, context: ContextTypes.DEFAULT_TYPE): """绑定授权账号。群内引导到私聊;私聊进入等待邮箱+Token 状态。""" user = update.effective_user + logger.info(f"🔗 收到绑定指令: user={user.id}, chat_type={update.effective_chat.type}") existing = await get_binding(user.id) if existing: text = ( @@ -32,13 +33,19 @@ async def cmd_bind(update: Update, context: ContextTypes.DEFAULT_TYPE): return if update.effective_chat.type != "private": - bot_username = context.bot.username or (await context.bot.get_me()).username + me = await context.bot.get_me() + bot_username = me.username url = f"https://t.me/{bot_username}?start=bind" keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("去私聊绑定", url=url)]]) - reply = await update.message.reply_text( - "🔐 为了保护 Token,请点击按钮到私聊完成绑定。", - reply_markup=keyboard, + text = ( + "🔐 为了保护 Token,请到私聊完成绑定。\n\n" + f"👉 点击进入:{url}" ) + try: + reply = await update.message.reply_text(text, reply_markup=keyboard, disable_web_page_preview=True) + except Exception as e: + logger.warning(f"🔗 绑定跳转按钮发送失败,改发普通文本: {type(e).__name__}: {e}") + reply = await update.effective_chat.send_message(text, disable_web_page_preview=True) asyncio.create_task(auto_delete(update.message, seconds=60)) asyncio.create_task(auto_delete(reply, seconds=60)) return