admin管理员组文章数量:1122846
I work with python telegram bot version more than 20. I'm trying to make when I choose option 1 it would send a message with my function and when i choose for example option 2 it would return other function.
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.ext import
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
keyboard = [
[
InlineKeyboardButton("Option 1", callback_data="1"),
InlineKeyboardButton("Option 2", callback_data="2"),
],
[InlineKeyboardButton("Option 3", callback_data="3"),]
]
reply_markup1 = InlineKeyboardMarkup(keyboard)
await update.message.reply_text('Hello!')
await update.message.reply_text('Choose one of options',reply_markup=reply_markup1)
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text("how can i help you")
async def button(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
query = update.callback_query
await query.answer()
await query.edit_message_text(text=f'Selected option: {query.data}')
if query.data == "1":
await query.message.reply_text(help_command)
It would look something like this in telegram:
Hello!
Choose one of options
(option 1)(option 2) ( option 3 )
[i select option 1]
how can i help you
Here's what error i get:
telegram.error.NetworkError: Unknown error in HTTP implementation: TypeError('Object of type function is not JSON serializable')
I don't remeber what i tried but i also got this error before:
AttributeError: 'NoneType' object has no attribute 'reply_text'
I saw a similar question but there is still no answer
本文标签: How to add function to InlineKeyboardButton in PythonTelegramBotStack Overflow
版权声明:本文标题:How to add function to InlineKeyboardButton in Python-Telegram-Bot? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308549a1933701.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论