# Код
import telebot
from telebot import types
bot = telebot.TeleBot('ХХХХХХХХХХХХХХХХХХХ')
@bot.message_handler(commands=['start'])
def start(_id):
markup = types.InlineKeyboardMarkup()
btn1 = types.InlineKeyboardButton('Да', callback_data='Ready')
btn2 = types.InlineKeyboardButton('Нет', callback_data='Stop')
markup.row(btn1, btn2)
bot.send_message(_id, '''Привет! Хочешь узнать какой ты психотип личности?
Тогда ответь на несколько вопросов. Ты готов?''', reply_markup=markup)
@bot.callback_query_handler(func=lambda callback: True)
def callback_btn(callback):
if callback.data == 'Ready':
questions(callback.message.chat.id)
elif callback.data == 'Stop':
bot.send_message(callback.message.chat.id, 'Ну может в другой раз)')
@bot.message_handler()
def questions(_id):
markup = types.ReplyKeyboardMarkup()
btn1 = types.InlineKeyboardButton('Конечно')
btn2 = types.InlineKeyboardButton('Нет люблю быть один')
btn3 = types.InlineKeyboardButton('Смотря какое общество')
markup.row(btn1, btn2)
markup.row(btn3)
bot.send_message(_id, 'Комфортно ли вам находиться в обществе?', reply_markup=markup)
bot.register_next_step_handler(_id, on_click)
def on_click(message, extrovert, introvert, ambivert):
if message.text == 'Конечно':
extrovert += 1
elif message.text == 'Нет люблю быть один':
introvert += 1
elif message.text == 'Смотря какое общество':
ambivert += 1
bot.polling(none_stop=True)
# Ошибка
2023-08-23 15:14:19,551 (__init__.py:1083 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: chat not found"
2023-08-23 15:14:19,551 (__init__.py:1085 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/__init__.py", line 1074, in __threaded_polling
self.worker_pool.raise_exceptions()
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/util.py", line 147, in raise_exceptions
raise self.exception_info
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/util.py", line 90, in run
task(*args, **kwargs)
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/__init__.py", line 6770, in _run_middlewares_and_handler
result = handler['function'](message)
File "/home/maksim/Загрузки/Python/Квест/Квест.py", line 33, in questions
bot.send_message(_id, 'Комфортно ли вам находиться в обществе?', reply_markup=markup)
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/__init__.py", line 1549, in send_message
apihelper.send_message(
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/apihelper.py", line 264, in send_message
return _make_request(token, method_url, params=payload, method='post')
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/apihelper.py", line 162, in _make_request
json_result = _check_result(method_name, result)
File "/home/maksim/.local/lib/python3.10/site-packages/telebot/apihelper.py", line 189, in _check_result
raise ApiTelegramException(method_name, result, result_json)
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: chat not found