Answer the question
In order to leave comments, you need to log in
How to make a button in a telegram bot a command?
Hello everyone, I'm trying my hand at writing bots. I got to the creation of keyboards and then ran into a dead end. I figured out how to add a keyboard with a replica, but I can’t find an answer on how to make it so that when you click on the keyboard button, a specific command is sent to the bot, not text. Here is my code:
import config
import telebot
from telebot import types
bot = telebot.TeleBot(config.token)
@bot.message_handler(commands=["start"])
def start(message):
kb = types.ReplyKeyboardMarkup()
kb.row('Реєстрація')
bot.send_message(message.chat.id, "Вітаю, я Ваш особистий помічник. Для подальшої роботи потрібно зареєструватися. Для реєстрації натисніть на вказівку з меню, або введіть команду /register", reply_markup=kb)
Answer the question
In order to leave comments, you need to log in
The Reply keyboard simply sends the text from the button, without any commands. You can simply do this:
@bot.message_handler(regexp='^Реєстрація$')
@bot.message_handler(commands=['register'])
def register(message):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question