What should I do.
Here is the code:
import telebot
data = {}
TOKEN = here is the bot token
bot = telebot.TeleBot(TOKEN)
def filter_echo(message):
return data[message.chat.id]['state'] == 'echo'
@bot.message_handler(commands=['start'])
def start_message(message):
data[message.chat.id] = {'state':'start'}
markup = telebot.types.InlineKeyboardMarkup()
button_echo = telebot.types.InlineKeyboardButton('Эхо-бот',callback_data='echo')
markup.add(button_echo)
bot.send_message(message.chat.id,message.from_user.first_name + ' нажми на кнопку',reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def commands(call):
bot.answer_callback_query(call.id)
if call.data == 'echo':
bot.send_message(call.message.chat.id, 'Напиши что-то')
data[call.message.chat.id]['state'] = 'echo'
@bot.message_handler(func=filter_echo)
def echo_message(message):
answer = message.text
bot.reply_to(message,answer)
bot.polling(none_stop=True)
And here is the terminal output
Traceback (most recent call last):
File "d:\code\bot.py", line 31, in <module>
bot.polling(none_stop=True)
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 620, in polling
self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 694, in __threaded_polling
raise e
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 649, in __threaded_polling
polling_thread.raise_exceptions()
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\util.py", line 107, in raise_exceptions
raise self.exception_info
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\util.py", line 89, in run
task(*args, **kwargs)
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 362, in __retrieve_updates
self.process_new_updates(updates)
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 448, in process_new_updates
self.process_new_messages(new_messages)
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 480, in process_new_messages
self._notify_command_handlers(self.message_handlers, new_messages, 'message')
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 3997, in _notify_command_handlers
if self._test_message_handler(message_handler, message):
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 3851, in _test_message_handler
if not self._test_filter(message_filter, filter_value, message):
File "C:\Users\olenik2\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 3883, in _test_filter
return filter_value(message)
File "d:\code\bot.py", line 7, in filter_echo
return data[message.chat.id]['state'] == 'echo'
KeyError: 525150753