Столкнулся с проблемой импорта
Вот сам код:
update_photo.py
from aiogram.dispatcher import FSMContext
from aiogram import types, Dispatcher
from aiogram.dispatcher.filters.state import StatesGroup, State
from aiogram.dispatcher.filters import Text
class ChangePhoto(StatesGroup):
new_photo = State()
async def updating(message: types.Message):
await message.answer("Пришлите новое фото")
await ChangePhoto.new_photo.set()
async def bad_new_photo(message: types.Message):
await message.reply(" Это не фотография")
return
async def new_photo_updated(message: types.Message, state: FSMContext):
await state.update_data(photo=message.photo[0].file_id)
data = await state.get_data()
await message.answer("Фото обновлено")
return db.update_user_photo(data['photo'], message.from_user.id)
def register_new_photo(dp: Dispatcher):
dp.register_message_handler(updating, Text(equals="Фотографию"))
dp.register_message_handler(bad_new_photo, lambda photo: not photo.photo, state=ChangePhoto.new_photo)
dp.register_message_handler(new_photo_updated, state=ChangePhoto.new_photo)
keyboard.py
from aiogram.types import ReplyKeyboardMarkup
kb = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
kb.add("Описание").add("Фотографию").add("Всю анкету")
main.py
from aiogram import types, Bot, Dispatcher
from aiogram.dispatcher.filters import Text
from aiogram.utils import executor
from src.states.update_photo import register_new_photo
from src.keyboards.kb_for_database import kb
import os
bot = Bot(token=os.getenv("TOKEN"))
dp = Dispatcher(bot=bot)
@dp.message_handler(Text(equals="Обновить анкету"))
async def update_users_form(message: types.Message):
await message.answer("Что желаете обновить?", reply_markup=kb)
@dp.message_handler(Text(equals="Фотографию"))
async def update_user_picture(message: types.Message):
register_new_photo(dp=dp)
if __name__ == '__main__':
executor.start_polling(dp)
Если запускаю код отдельно в в файле update.py, то работает без проблем