@h3ko

Почему высвечивается ошибка импорта файла?

почему высвечивается эта ошибка когда запускаю код?
"ImportError: cannot import name 'F' from 'aiogram' (C:\Users\PC\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\__init__.py)"

Вот сам код, за ранее спасибо.

from aiogram import Bot, Dispatcher, F
from aiogram.types import ChatJoinRequest
import logging
import contextlib
import asyncio


CHANNEL_ID = '******'
ADMIN_ID = '*****'



async def approve_request(chat_join: ChatJoinRequest, bot: Bot, message):
    msg = f'Привет, {message.from_user.first_name}'
    await bot.send_message(chat_id=chat_join.from_user.id, text=msg)
    await chat_join.approve()

async def start():
    logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)s - [%(levelname)s] - %(name)s - (%(filename)s).%(funcName)s(%(lineno)d) - %(message)s')

    bot: Bot = Bot('6011872825:AAFlMJwGxoi5nYKN82HzlSVUwKv3vkad9Bg')
    dp = Dispatcher(bot)
    dp.chat_join_request.register(approve_request, F.chat.id ==CHANNEL_ID)


    try:
        await dp.start_polling(bot, allowed_updates=dp.resolve_used_update_types())
    except Exception as ex:
        logging.error(f'[Exception] - {ex}', exc_info=True)
    finally:
        await bot.session.close()



if __name__ == '__main__':
    with contextlib.suppress(KeyboardInterrupt, SystemExit):
        asyncio.run(start())
  • Вопрос задан
  • 684 просмотра
Решения вопроса 1
hottabxp
@hottabxp
Сначала мы жили бедно, а потом нас обокрали..
Попробуйте заменить первую строку на from aiogram import Bot, Dispatcher
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы