Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Если кому-то хочется увидеть статью про более сложного бота (с вебхуками, подключенной БД с настройками пользователей и т.д.) — пишите.
Про интерфейс для админа немного не понял.
Если кому-то хочется увидеть статью про более сложного бота (с вебхуками, подключенной БД с настройками пользователей и т.д.) — пишите.
И, не забываем зайти на гитхаб и удалить TOKEN из нашего bot.py. Ведь нам не нужно, чтобы кто-то им пользовался.
while True:
try:
tb.polling(none_stop=True)
except Exception as e:
logger.error(e)
time.sleep(15)

File "/usr/local/lib/python3.5/dist-packages/telebot/__init__.py", line 129, in get_updates
json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates)
File "/usr/local/lib/python3.5/dist-packages/telebot/apihelper.py", line 175, in get_updates
return _make_request(token, method_url, params=payload)
File "/usr/local/lib/python3.5/dist-packages/telebot/apihelper.py", line 54, in _make_request
timeout=(connect_timeout, read_timeout), proxies=proxy)
File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 433, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30)Про падения
During handling of the above exception, another exception occurred:
...
r = adapter.send(request, **kwargs)
File "/home/user/.local/lib/python3.6/site-packages/requests/adapters.py", line 521, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30)
Process finished with exit code 1
isRunning = 0
def JustAFunction(arg):
global isRunning
isRunning = True
#some code...
@bot.message_handler(commands=['start', 'go'])
def start_handler(message):
global isRunning
if not isRunning:
chat_id = message.chat.id
text = message.text
msg = bot.send_message(chat_id, 'Сколько вам лет?')
bot.register_next_step_handler(msg, askAge) #askSource
isRunning = True@bot.message_handler(commands=['start', 'go'])
def start_handler(message):
global isRunning
if not isRunning:
chat_id = message.chat.id
text = message.text
msg = bot.send_message(chat_id, 'Сколько вам лет?')
bot.register_next_step_handler(msg, askAge) #askSource
isRunning = True
print(isRunning)
print(isRunning)
bot.register_next_step_handler заканчивает выполнение функции. Честно, не лазил по коде telebot-а, не могу быть уверен на 100%@bot.message_handler(commands=['start', 'go'])
def start_handler(message):
global isRunning
if not isRunning:
isRunning = True
chat_id = message.chat.id
text = message.text
msg = bot.send_message(chat_id, 'Сколько вам лет?')
bot.register_next_step_handler(msg, askAge) #askSourcebot.polling(none_stop=True, interval=0, timeout=10requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=40)
Создание и хостинг телеграм бота. От А до Я