Всем привет. Переписал код с telebot на aiogram.
Код на telebot (рабочий):
import telebot
from telebot import types
bot = telebot.TeleBot('api')
@bot.message_handler(commands=['start'])
def start(message):
bot.send_message(message.chat.id,
f'''
<b>Привет, {message.from_user.first_name}!
Добро пожаловать в Potato Team!</b>''', parse_mode = 'html', reply_markup = start_menu)
start_menu = types.InlineKeyboardMarkup(row_width=2)
start_menu.add(
types.InlineKeyboardButton(text='Помощь', callback_data='help'))
@bot.callback_query_handler(func=lambda call: True)
def help(call):
if call.data == 'help':
bot.send_message(call.message.chat.id, f'''
<b>Админ/Тех.Поддержка: @barltg</b>''', parse_mode = 'html', reply_markup = backtomenu)
elif call.data == 'back':
bot.send_message(call.message.chat.id,
f'''
<b>Привет, {call.from_user.first_name}!
Добро пожаловать в Potato Team!</b>''', parse_mode = 'html', reply_markup = start_menu)
backtomenu = types.InlineKeyboardMarkup(row_width=2)
backtomenu.add(
types.InlineKeyboardButton(text='Назад', callback_data='back'))
print("Успешный запуск!")
bot.polling(none_stop = True)
Код на aiogram (переписанный мною, с ошибками):
import logging
from aiogram import Bot, Dispatcher, executor, types
bot = Bot(token = 'api' )
logging.basicConfig(level=logging.INFO)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
await message.answer(f'''
<b>Привет, {message.from_user.first_name}!
Добро пожаловать в Potato Team!</b>''', parse_mode = 'html', reply_markup=start_menu)
start_menu = types.InlineKeyboardMarkup(row_width=2)
start_menu.add(
types.InlineKeyboardButton(text='Помощь', callback_data='help'))
back = types.InlineKeyboardMarkup(row_width=2)
back.add(types.InlineKeyboardButton(text='Назад', callback_data='back'))
@dp.callback_query_handler(lambda call: True)
async def help(call: types.CallbackQuery):
if call.back == 'help':
await message.answer(f'''
<b>Админ/Тех.Поддержка - @barltg</b>''', parse_mode = 'html', reply_markup=start_menu)
elif call.back == 'back':
await message.answer(call.message.chat.id, f'''
<b>Привет, {message.from_user.first_name}!
Добро пожаловать в Potato Team!</b>''', parse_mode = 'html',reply_markup=start_menu)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)
Сама ошибка:
File "<string>", line 24, in help
AttributeError: 'CallbackQuery' object has no attribute 'back'
Как её исправить?