You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python开发Telegram Bot:如何让群成员手机后台打开指定网站

实现Telegram Bot引导群成员打开指定网站的方案

首先明确:Telegram Bot没有权限直接强制打开用户设备上的浏览器,这是平台出于用户隐私和安全的硬性限制,所有打开网站的操作必须由用户主动触发。你可以通过以下两种友好的方式引导群成员访问指定的群规网站:

方案一:发送带链接的引导消息

直接在回复中插入网站链接,Telegram会自动识别为可点击的跳转链接,用户点击后即可在浏览器打开网站。

修改后的代码示例:

import os
import telebot

my_secret = os.environ['API_KEY']
bot = telebot.TeleBot(my_secret)

@bot.message_handler(commands=['Greet'])
def greet(message):
    # 替换为你的群规网站链接
    rules_url = "https://your-rules-site.com"
    # 发送带链接的欢迎消息
    reply_content = f"欢迎入群!请查看群规:{rules_url}"
    bot.send_message(message.chat.id, reply_content)

bot.polling()

方案二:发送带内联按钮的消息(体验更友好)

使用Telegram的内联键盘按钮,让用户点击按钮直接打开网站,交互更直观。

修改后的代码示例:

import os
import telebot
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton

my_secret = os.environ['API_KEY']
bot = telebot.TeleBot(my_secret)

@bot.message_handler(commands=['Greet'])
def greet(message):
    rules_url = "https://your-rules-site.com"
    # 创建内联键盘按钮
    keyboard = InlineKeyboardMarkup()
    keyboard.add(InlineKeyboardButton("点击查看群规", url=rules_url))
    # 发送带按钮的引导消息
    bot.send_message(
        message.chat.id,
        "欢迎入群!请查看下方群规:",
        reply_markup=keyboard
    )

bot.polling()

额外优化建议

如果是针对新入群成员自动触发引导,可以替换消息处理器为新成员加入事件,无需手动发送/Greet命令:

@bot.message_handler(content_types=['new_chat_members'])
def welcome_new_member(message):
    rules_url = "https://your-rules-site.com"
    keyboard = InlineKeyboardMarkup()
    keyboard.add(InlineKeyboardButton("点击查看群规", url=rules_url))
    bot.send_message(
        message.chat.id,
        f"欢迎@{message.new_chat_members[0].username}入群!请查看群规:",
        reply_markup=keyboard
    )

内容的提问来源于stack exchange,提问作者yxngkxng 480

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 18:53:13