Answer the question
In order to leave comments, you need to log in
Telegram bot keeps crashing, how to solve?
The bot crashes after some time from this error: Bot
code:
import telebot
from telebot import types
import random
import config
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def welcome(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("случайная картинка")
item2 = types.KeyboardButton("создатель")
markup.add(item1, item2)
bot.send_message(message.chat.id, "добро пожаловать!\nя - бот лошара".format(message.from_user, bot.get_me()), reply_markup=markup,
parse_mode='html')
@bot.message_handler(content_types=['text'])
def gu(message):
if message.chat.type == 'private':
if message.text == 'случайная картинка':
number = str(random.randint(1, 5))
if number == '1':
photo = open('C:\матвей\c.jpg', 'rb')
bot.send_photo(message.chat.id, photo)
bot.send_message(message.chat.id, 'Лукака')
elif number == '2':
photo2 = open('C:\матвей\wow.jpg', 'rb')
bot.send_photo(message.chat.id, photo2)
bot.send_message(message.chat.id, 'уха')
elif number == '3':
photo3 = open('C:\матвей\gori.jpg', 'rb')
bot.send_photo(message.chat.id, photo3)
bot.send_message(message.chat.id, 'gorrilaz')
elif number == '4':
photo4 = open('C:\матвей\phototest.jpg', 'rb')
bot.send_photo(message.chat.id, photo4)
bot.send_message(message.chat.id, 'Мой рисунок')
elif number == '5':
photo5 = open('C:\матвей\onime.png', 'rb')
bot.send_photo(message.chat.id, photo5)
bot.send_message(message.chat.id, 'Аниме женщина')
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Try in at the end instead of bot.poling it
if __name__ == '__main__':
while True:
try:
bot.polling(none_stop=True)
except Exception as e:
time.sleep(3)
print(e)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question