Answer the question
In order to leave comments, you need to log in
Why doesn't the telegram bot start?
import telebot
from telebot import types
import random
token = '**'
bot = telebot.TeleBot(token)
@bot.message_handler(commands = ['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
item1 = types.KeyboardButton('Рандомное число')
item2 = types.KeyboardButton('Офисный пк')
item3 = types.KeyboardButton('Игровой пк')
markup.add(item1, item2, item3)
bot.send_message(message.chat.id, 'Привет', reply_markup = markup)
@bot.message_handler(content_types = ['text'])
def bot_message(message):
if message.text == 'Рандомное число':
bot.send_message(message.chat.id, 'ваше число: ' +str(random.randint(0, 1000)))
elif message.text == 'Офисный пк':
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
item1 = types.KeyboardButton('сборка')
item2 = types.KeyboardButton('сборка такая то')
back = types.KeyboardButton('назад')
markup.add(item1, item2, back)
bot.send_message(message.chat.id, 'Офисный пк', reply_markup = markup)
elif message.text == 'Игровой пк':
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
item1 = types.KeyboardButton('Комлектующие')
item2 = types.KeyboardButton('Комлектующие такие то')
back = types.KeyboardButton('назад')
markup.add(item1, item2, back)
bot.send_message(message.chat.id, 'Игровой пк', reply_markup = markup)
elif message.text == 'Назад':
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
item1 = types.KeyboardButton('Рандомное число')
item2 = types.KeyboardButton('Офисный пк')
item3 = types.KeyboardButton('Игровой пк')
markup.add(item1, item2, item3)
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
Try this design
if __name__ == '__main__':
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