Answer the question
In order to leave comments, you need to log in
How to make an inline button on the telebot library tied to your message?
Hello.
I am studying the telebot library from videos, I have not found in any one how to bind an inline button to old variables.
For example:
I am writing a telegram to the /hi bot, he offers me to buy 1 issue of the comic. with inline button. I change the comic number variable, I write /hi again, it offers me to buy the second issue of the comic with an inline button. When you click on the inline button of the first issue, it provides a link to buy the second, not the first.
import telebot
from telebot import types
number = 1
bot = telebot.TeleBot("BotApi")
@bot.message_handler(commands=["new"])
def new(message):
global number
number = number + 1
bot.send_message(message.chat.id, "Номер комикса изменён на +1" )
@bot.message_handler(commands=["hi"])
def hi(message):
markup = telebot.types.InlineKeyboardMarkup(row_width=1)
ravage = telebot.types.InlineKeyboardButton(text='Купить', callback_data="buy")
markup.add(ravage)
komiks = "Жоский супергерой № " + str(number)
bot.send_message(message.chat.id, "Появился новый комикс " + komiks, reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def callback(call):
if call.message:
if call.data == "buy":
kupit = bot.send_message(call.message.chat.id, 'Введите количество выпусков')
bot.register_next_step_handler(kupit, lessgo)
def lessgo(message):
komiks = "Жоский супергерой № " + str(number)
bot.send_message(message.chat.id, "Вы хотите купить комикс " + komiks +", "+ message.text + " выпусков будет куплено")
bot.send_message(message.chat.id, "Купить комикс вы можете по ссылке\n testkomiks800.ru/kupit"+str(number))
bot.polling()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question