from aiogram import types, Dispatcher
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
class FSMAdmin(StatesGroup):
photo = State()
name = State()
description = State()
price = State()
# Начало диалога и загрузка нового пункта меню
# @dp.message_handler(commands='Загрузить', state=None)
async def cm_start(message: types.Message):
await FSMAdmin.photo.set()
await message.reply('Загрузи фото')
# Первый ответ и пишем словарь
# @dp.message_handler(content_types=['photo'], state= FSMAdmin.photo)
async def load_photo(message: types.Message, state: FSMContext):
data = await state.proxy()
data['photo'] = message.photo[0].file_id
await FSMAdmin.next()
data = await state.proxy()
await message.repyl(str(data))
await state.finish()
# Второй ответ
# @dp.message_handler(state=FSMAdmin.name)
async def load_name(message: types.Message, state: FSMContext):
data = await state.proxy()
data['name'] = message.photo[0].file_id
await FSMAdmin.next()
await message.reply("Введите описание")
# Трети ответ
# @dp.message_handler(state=FSMAdmin.description)
async def load_description(message: types.Message, state: FSMContext):
data = await state.proxy()
data['description'] = message.photo[0].file_id
await FSMAdmin.next()
await message.reply("Теперь введите название")
# Четвертый ответ и используем полученные данный
# @dp.message_handler(state=FSMAdmin.price)
async def load_price(message: types.Message, state: FSMContext):
data = await state.proxy()
data['price'] = float(message.text)
await FSMAdmin.next()
# @dp.message_handler(state="*", commands='Отмена')
# @dp.message_handler(Text(equals='Отмена', jgnore_case=True), state='*')
async def cancel_handler(message: types.Message, state: FSMContext):
current_state = await state.get_state()
if current_state is None:
return
await state.finish()
await message.reply('ОК')
def register_handlers_admin(dp: Dispatcher):
dp.register_message_handler(cm_start, commands=['Загрузить'], state=None)
dp.register_message_handler(load_photo, content_types=['photo'], state=FSMAdmin.photo)
dp.register_message_handler(load_name, state=FSMAdmin.name)
dp.register_message_handler(load_description, state=FSMAdmin.description)
dp.register_message_handler(load_price, state=FSMAdmin.price)
Не могу понять в чем ошибка (извините за столь очевидный вопрос 'просто я новичек' )
Сама ошибка:
C:\BT\pizza_at_home\venv\lib\site-packages\aiogram\dispatcher\filters\state.py:57: FSMStorageWarning: You haven’t set any storage yet so no states and no data will be saved.
You can connect MemoryStorage for debug purposes or non-essential data.
await state.set_state(self.state)