import telebot from telebot import types TOKEN =…
- User
import telebot from telebot import types
TOKEN = '6668161332:AAGoDic9hlPdLWsob0M3xPH-wOz8ngFOPK0' bot = telebot.TeleBot(TOKEN)
zaproses = 10 subscribe = "Нет подписки"
@bot.message_handler(commands=['start']) def menu(message): markup = types.InlineKeyboardMarkup() markup.add(types.InlineKeyboardButton("Профиль", callback_data='menu')) bot.send_message(message.chat.id, 'Меню\nВыберите пункт.', parse_mode='html', reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True) def shop(call): shopback = types.InlineKeyboardMarkup() shopback.add(types.InlineKeyboardButton("", callback_data='menu')) bot.send_message(call.message.chat.id, 'Магазин:\nТекст 1:\n 100 RUB \n Текст 2:\n 250 RUB\nТекст 3:\n 400 RUB \n Текст 4:\n 500 RUB', parse_mode='html', reply_markup=shopback)
@bot.callback_query_handler(func=lambda call: True) def handle_query(call): global zaproses global subscribe if call.data == 'profile': markupadds = types.InlineKeyboardMarkup() menub = types.InlineKeyboardButton("🔙 Назад", callback_data='menu') shopb = types.InlineKeyboardButton("💷 Пополнить 💷", callback_data='shop') markupadds.add(menub, shopb) bot.send_message(call.message.chat.id, f'Это ваш профиль,\nваш ID: {call.from_user.id}\nУ вас: {zaproses} Запросов\nВаши подписки: {subscribe}', parse_mode='html', reply_markup=markupadds) elif call.data == 'menu': menu(call.message)
bot.polling(none_stop=True) бот выдает следующую ошибку "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Scripts\python.exe" "C:\Users\Dell alienware\PycharmProjects\BotTG\main.py" 2023-09-14 19:27:16,332 (init.py:1083 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: can't parse entities: Unexpected end tag at byte offset 64" 2023-09-14 19:27:16,333 (init.py:1085 MainThread) ERROR - TeleBot: "Exception traceback: Traceback (most recent call last): File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\site-packages\telebot_init_.py", line 1074, in _threaded_polling self.worker_pool.raise_exceptions() File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\site-packages\telebot\util.py", line 147, in raise_exceptions raise self.exception_info File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\site-packages\telebot\util.py", line 90, in run task(*args, **kwargs) File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\site-packages\telebot_init.py", line 6788, in run_middlewares_and_handler result = handler'function' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dell alienware\PycharmProjects\BotTG\main.py", line 21, in shop bot.send_message(call.message.chat.id, 'Магазин:\nТекст 1:\n 100 RUB \n Текст 2:\n 250 RUB\nТекст 3:\n 400 RUB \n Текст 4:\n 500 RUB', parse_mode='html', reply_markup=shopback) File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\site-packages\telebot_.py", line 1549, in send_message apihelper.send_message( File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\site-packages\telebot\apihelper.py", line 264, in send_message return _make_request(token, method_url, params=payload, method='post') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\site-packages\telebot\apihelper.py", line 162, in _make_request json_result = _check_result(method_name, result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Dell alienware\PycharmProjects\BotTG\venv\Lib\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: can't parse entities: Unexpected end tag at byte offset 64 "
- Assistant
The issue seems to be with the code in the
shopfunction where you are handling the callback query. Currently, you have two callback query handlers in your code, and both have the same function signaturefunc=lambda call: True. This means that both handlers will be triggered for any callback query.To fix the issue, you can modify your code to have separate handlers for different callback queries. Here's an example:
@bot.callback_query_handler(func=lambda call: call.data == 'profile') def handle_profile(call): markupadds = types.InlineKeyboardMarkup() menub = types.InlineKeyboardButton("🔙 Назад", callback_data='menu') shopb = types.InlineKeyboardButton("💷 Пополнить 💷", callback_data='shop') markupadds.add(menub, shopb) bot.send_message(call.message.chat.id, f'Это ваш профиль,\nваш ID: {call.from_user.id}\nУ вас: {zaproses} Запросов\nВаши подписки: {subscribe}', parse_mode='html', reply_markup=markupadds) @bot.callback_query_handler(func=lambda call: call.data == 'menu') def handle_menu(call): menu(call.message) @bot.callback_query_handler(func=lambda call: call.data == 'shop') def handle_shop(call): shopback = types.InlineKeyboardMarkup() shopback.add(types.InlineKeyboardButton("", callback_data='menu')) bot.send_message(call.message.chat.id, '<b>Магазин:\nТекст 1:\n</b> 100 RUB \n Текст 2:\n</b> 250 RUB\nТекст 3:\n</b> 400 RUB \n Текст 4:\n</b> 500 RUB', parse_mode='html', reply_markup=shopback)