Telegram python bot(远程机器人库)

问题描述 投票:0回答:1

我在 python 上使用 telebot 库作为我的电报机器人。我需要在单击

InlineKeyboardButton
中的第一个按钮 (
markup
) 时,应显示另一个带有几个按钮 (
InlineKeyboardMarkup
) 的标记。

import telebot
from telebot import types


#BOT CONNECT
bot = telebot.TeleBot('token')

#markups
markup = types.InlineKeyboardMarkup()
markup.add(types.InlineKeyboardButton("Почати ", ))
markup.add(types.InlineKeyboardButton("Show guide",url=""))


@bot.message_handler(commands=['start'])
def start(message):
    bot.send_message(
        message.chat.id, "Бот буде надсилати вам вибірку найголовніших новин на вибрану вами тему у вибраний час", reply_markup=markup)


# RUN
bot.infinity_polling()
python bots telegram-bot telebot
1个回答
0
投票
keyboard.add(types.InlineKeyboardButton("Почати", callback_data="test"))

keyboard.add(types.InlineKeyboardButton(text="Почати", callback_data="test"))

@bot.callback_query_handler(func=lambda call: True)
def testing(call):
  if call.data == "test":
     bot.send_message(call.chat_id, "send text")
  else:
     pass

像这样打开按钮并像这样检查不要忘记放置decarator

© www.soinside.com 2019 - 2024. All rights reserved.