I`m just create the template list
import logging
from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor
logging.basicConfig(level=logging.INFO)
API_TOKEN = "12345:YOUR_TOKEN"
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
class Template:
def __init__(self):
self.tmp = []
def set(self, arg: object):
self.tmp.append(arg)
def get(self):
return self.tmp.pop()
message_tmp = Template()
i_need_this_info_tmp = Template()
@dp.message_handler()
async def first(message=types.Message):
markup = types.InlineKeyboardMarkup(resize_keyboard=True, selective=True)
markup.add(types.InlineKeyboardButton('Фото ??', callback_data='btn1'))
markup.add(types.InlineKeyboardButton('Video ??', callback_data='btn2'))
i_need_this_info = await message.answer('get choice', reply_markup=markup)
i_need_this_info_tmp.set(i_need_this_info)
print(message.message_id)
message_tmp.set(message)
@dp.callback_query_handler(lambda call: True)
async def second(callback_query: types.CallbackQuery):
code = callback_query.data.replace('btn', '')
message = message_tmp.get()
i_need_this_info = i_need_this_info_tmp.get()
print(message.message_id)
if code == '1':
await message.answer("first")
elif code == '2':
await message.answer("second")
await bot.delete_message(message.from_user.id, i_need_this_info.message_id)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…