Traceback (most recent call last):
File "/home/Joerr/main.py", line 41, in <module>
bot.polling(True, 0)
File "/home/Joerr/.local/lib/python3.13/site-packages/telebot/__init__.py", line 1198, in polling
self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout, logger_level=logger_level, allowed_updates=allowed_updates)
File "/home/Joerr/.local/lib/python3.13/site-packages/telebot/__init__.py", line 1273, in __threaded_polling
raise e
File "/home/Joerr/.local/lib/python3.13/site-packages/telebot/__init__.py", line 1235, in __threaded_polling
self.worker_pool.raise_exceptions()
File "/home/Joerr/.local/lib/python3.13/site-packages/telebot/util.py", line 150, in raise_exceptions
raise self.exception_info
File "/home/Joerr/.local/lib/python3.13/site-packages/telebot/util.py", line 93, in run
task(*args, **kwargs)
File "/home/Joerr/.local/lib/python3.13/site-packages/telebot/__init__.py", line 9759, in _run_middlewares_and_handler
result = handler['function'](message)
File "/home/Joerr/main.py", line 31, in start
keyboard.add(locals()['btn' + str(i)])
KeyError: 'btn0'
import telebot
import random
bot =telebot.TeleBot('7520081425:AAHXql0mtqLFCQBxSwQxa vdwRgrL-tyAHWg')
@bot.callback_query_handler(func=lambda call: call.data == 'right')
def right(message):
bot.send_message(message.from_user.id, "✅Правильно✅")
start(message)
@bot.callback_query_handler(func=lambda call: call.data == 'false')
def false(message):
bot.send_message(message.from_user.id, "❌Попробуй еще раз❌")
@bot.message_handler(commands=['start'])
def start(message):
c=random.randint(0, len(a)-1)
f=a[c]
print(f)
b=f[:-2]
print(b)
keyboard = telebot.types.InlineKeyboardMarkup()
g=f[-1]
print(g)
j=[]
for i in range(len(b)):
if str(i)==g:
k=b[i]
locals()['btn' + str(i)] = telebot.types.InlineKeyboardButton(k, callback_data='right')
keyboard.add(locals()['btn' + str(i)])
else:
k=b[i]
locals()['btn' + str(i)] = telebot.types.InlineKeyboardButton(k, callback_data='false')
keyboard.add(locals()['btn' + str(i)])
bot.send_message(message.from_user.id, "Выбери букву на которую падает ударение", reply_markup=keyboard)
f=open('база2.txt', encoding='utf-8')
s=f.readlines()
a=[]
for i in s:
a.append(i[:-1])
bot.polling(True, 0)