D
D
Dimitri Pun2020-12-20 22:57:21
Python
Dimitri Pun, 2020-12-20 22:57:21

Python (telebot) how can I make the activation of a variable when a certain function is called or? Is it necessary to check whether the keyboard is active in the bot or not!?

How to make a variable to be activated when a certain function is called?
How to check if a variable is active in some function or class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2020-12-21
@ggg331

Without knowing how you implemented it, it's hard to say. As far as I understand, the speech is still about ReplyKeyboardMarkup. You can use, for example, a dictionary (or a class for storing data) to store states. And for each keyboard put down the state. Conditionally

states = {"kb":None}

def ... клавиатура1
    keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
    button1 = telebot.types.KeyboardButton(f'Да')
    button2 = telebot.types.KeyboardButton(f'Нет')
    keyboard.row(button1, button2)
    states["kb"] = "kb1"
    bot.send_message(message.chat.id, message, reply_markup=keyboard)

def ... клавиатура2
    keyboard = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
    button1 = telebot.types.KeyboardButton(f'Да')
    button2 = telebot.types.KeyboardButton(f'Нет')
    keyboard.row(button1, button2)
    states["kb"] = "kb2"
    bot.send_message(message.chat.id, message, reply_markup=keyboard)

@bot.message_handler(content_types=['text'])
def echo_text(message):
    if states["kb"] == "kb1":
        if message.text == 'Да':
    elif states["kb"] == "kb2":
        if message.text == 'Да':

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question