Answer the question
In order to leave comments, you need to log in
How to rewrite code from telebot to aiogram?
Hello. Rewrote the code from telebot to aiogram.
Code on telebot (working):
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)
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'
Answer the question
In order to leave comments, you need to log in
Correct
CallbackQuery
spelling Pay attention to the case of letters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question