K
K
Kto Takoi2021-09-05 23:13:24
Python
Kto Takoi, 2021-09-05 23:13:24

Is it possible to create 2 buttons in a telegram bot?

Hello, I apologize for the stupid question and request. Is it possible to make the bot, when you start working with it, have a Reply button where, by clicking on it, the first Reply keyboard is removed and a new one is added.
By type, you enter the command / start appears in place of the keyboard 3 buttons (one, two, three) and for example I press the "one" button and all 3 buttons are deleted and buttons appear instead of them for example (do you want again?, exactly you?) when there, for example, you press the "two" button, so all the buttons are deleted and new buttons appear that already go specifically for the "two" button and the same with the third button.

If you can do this, please give a link to the resource where it is shown how to do it or throw the code.
I will be very grateful!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2021-09-06
@Lepeshka

Can

P
Python Newbie, 2021-09-06
@Levman5

Here is an example:

import telebot
from telebot.types import Message

from telebot import types

client = telebot.TeleBot('Твой токен')


@client.message_handler(commands=['start'])
def welcom(message):
    markup_reply = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item_1 = types.KeyboardButton('1')
    item_2 = types.KeyboardButton('2')
    item_3 = types.KeyboardButton('3')
    markup_reply.add(item_1, item_2, item_3)
    
    client.send_message(message.chat.id, 'Нажми на кнопку', reply_markup=markup_reply)


@client.message_handler(content_types=['text'])
def text(message):
    if message.text == '1':
        markup_reply = types.ReplyKeyboardMarkup(resize_keyboard=True)
        item_1 = types.KeyboardButton('Ты уверен')
        item_2 = types.KeyboardButton('тест')
        
        markup_reply.add(item_1, item_2)
        
        client.send_message(message.chat.id, 'Ты нажал на кнопку', reply_markup=markup_reply)
    elif message.text == '2':
        markup_reply = types.ReplyKeyboardMarkup(resize_keyboard=True)
        item_1 = types.KeyboardButton('ха')
        item_2 = types.KeyboardButton('пицца')
        
        markup_reply.add(item_1, item_2)
        
        client.send_message(message.chat.id, 'Ты нажал на кнопку2', reply_markup=markup_reply)

client.polling(none_stop=True, interval=0)

You can run and check

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question