如何在inlinekeyboardbutton python电报中同时使用callback_data和url

发布于 2025-02-04 13:32:25 字数 395 浏览 2 评论 0 原文

我想计算有多少用户单击一个按钮,然后我使用了callback_data:

for n in list2 :
     buttons.append([InlineKeyboardButton(n[0], callback_data=f"click on { n[0] }" , url = "https://t.me/test")])
context.bot.send_message(chat_id=update.effective_chat.id, reply_markup=InlineKeyboardMarkup(buttons), text="List of my channals")

该按钮确实打开了URL,但它不会发出回调请求,当我删除URL参数回调时,请按预期工作...同时使用两个参数的方法?

I want to count how many users clicked on a button and I used callback_data for it :

for n in list2 :
     buttons.append([InlineKeyboardButton(n[0], callback_data=f"click on { n[0] }" , url = "https://t.me/test")])
context.bot.send_message(chat_id=update.effective_chat.id, reply_markup=InlineKeyboardMarkup(buttons), text="List of my channals")

the button does open the URL but it doesn't make a callback request and when I delete the url parameter callback works as expected ... is there a way to use both parameters at the same time ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

私藏温柔 2025-02-11 13:32:25

我试图做同样的事情,但是显然你不能。 callback_data和URL是相互排斥的参数。

您可以在此处找到更多信息:

I was trying to do the same thing, but apparently you can't. The callback_data and url are mutually exclusive arguments.

You can find more info here: https://docs.python-telegram-bot.org/en/stable/telegram.inlinekeyboardbutton.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文