Answer the question
In order to leave comments, you need to log in
Why does the Telegram bot give an error message when clicking on the buttons?
Why, when I click on the start, it writes the message that I indicated, it gives out the keyboard too. But for example, if I click on any button, it displays a message from def welcome
import telebot
from telebot import types
bot = telebot.TeleBot('ТУТ ТОКЕН')
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
butt1 = types.KeyboardButton('ЗАРАБОТАТЬ')
butt2 = types.KeyboardButton('КАНАЛ')
markup.add(butt1, butt2)
markup2 = types.ReplyKeyboardMarkup(resize_keyboard = True)
butt1 = types.KeyboardButton('Дальше')
butt2 = types.KeyboardButton('Назад')
markup2.add(butt1, butt2)
@bot.message_handler(content_types = ['text'])
def welcome(message):
bot.send_message(message.chat.id, 'Привет епта ', reply_markup = markup)
@bot.message_handler(content_types= ['text'])
def start(message):
bot.send_message(message.chat.id, 'Ага', reply_markup = markup)
if message.text == 'ЗАРАБОТАТЬ':
bot.send_message(message.chat.id, 'Что-бы заработать подними жопу', reply_markup = markup2)
elif message.text =='КАНАЛ':
bot.send_message(message.chat.id, 'Это наш канал', reply_markup = markup2)
def lala(message):
if message.text == 'Дальше':
bot.send_message(message.chat.id, 'Ага ага')
elif message.text == 'Назад':
bot.send_message(message.chat.id, 'Вы вернулись', reply_markup = markup)
bot.polling(none_stop = True)
Answer the question
In order to leave comments, you need to log in
In the decorator, you specify that it will work on any text coming to the bot. Text you send via buttons. Also, the start function is under exactly the same decorator.
Should be replaced by :
Specified without changing anything
import telebot
from telebot import types
bot = telebot.TeleBot('ТУТ ТОКЕН')
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
butt1 = types.KeyboardButton('ЗАРАБОТАТЬ')
butt2 = types.KeyboardButton('КАНАЛ')
markup.add(butt1, butt2)
markup2 = types.ReplyKeyboardMarkup(resize_keyboard = True)
butt1 = types.KeyboardButton('Дальше')
butt2 = types.KeyboardButton('Назад')
markup2.add(butt1, butt2)
@bot.message_handler(content_types = ['text']) # Здесь вы указываете декоратор
def welcome(message):
bot.send_message(message.chat.id, 'Привет епта ', reply_markup = markup)
@bot.message_handler(content_types= ['text']) # Здесь заменить
def start(message):
bot.send_message(message.chat.id, 'Ага', reply_markup = markup)
if message.text == 'ЗАРАБОТАТЬ':
bot.send_message(message.chat.id, 'Что-бы заработать подними жопу', reply_markup = markup2)
elif message.text =='КАНАЛ':
bot.send_message(message.chat.id, 'Это наш канал', reply_markup = markup2)
def lala(message):
if message.text == 'Дальше':
bot.send_message(message.chat.id, 'Ага ага')
elif message.text == 'Назад':
bot.send_message(message.chat.id, 'Вы вернулись', reply_markup = markup)
bot.polling(none_stop = True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question