@ert12

AttributeError: module 'aiogram.types.message' has no attribute 'from_user'. Библиотека aiogram. Как задать user_id в scheduler?

from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher, FSMContext
from aiogram.utils import executor
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from apscheduler.schedulers.asyncio import AsyncIOScheduler

from config import TOKEN
from parse_news import ParseNews
from sqlighter import SQLighter
import asyncio

bot = Bot(token=TOKEN, parse_mode=types.ParseMode.MARKDOWN)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
scheduler = AsyncIOScheduler()
db = SQLighter('db.db')

pn = ParseNews


class Info(StatesGroup):
    login = State()
    password = State()


@dp.message_handler(commands=["start"])
async def welcome(message: types.Message):
    await message.answer('Увійдіть у свій кабінет на сайті nz.ua')
    await message.answer('Введіть свій логін')
    await Info.login.set()


@dp.message_handler(state=Info.login)
async def process_login(message: types.Message, state: FSMContext):
    await state.update_data(login=message.text)
    await message.answer("Введіть свій пароль")
    await Info.next()


@dp.message_handler(state=Info.password)
async def process_password(message: types.Message, state: FSMContext):
    await state.update_data(password=message.text)
    user_data = await state.get_data()
    if not db.subscriber_exists(message.from_user.id):
        db.add_user_info(message.from_user.id, user_data['login'], user_data['password'])
    else:
        db.update_user_info(user_data['login'], user_data['password'], message.from_user.id)
    await Info.next()
    await bot.send_message(message.from_user.id, pn.parse_news(pn, user_data['login'], user_data['password']))
    await state.finish()


@dp.message_handler(commands=['news'])
async def show_news(message: types.Message):
    await bot.send_message(message.from_user.id,
                           pn.parse_news(pn, db.get_login(message.from_user.id), db.get_password(message.from_user.id)))
    print(db.get_login(message.from_user.id), db.get_password(message.from_user.id))


async def check(message: types.message):
    while True:
        # await asyncio.sleep(wait_for)

        count = pn.check_new(pn, db.get_login(message.from_user.id), db.get_password(message.from_user.id))
        if count is not None:
            await dp.bot.send_message(message.from_user.id, f'Нових новин: {count}')


def schedule_jobs():
    scheduler.add_job(check, 'interval', seconds=20, args=(types.message,))


async def on_startup(dp):
    schedule_jobs()


if __name__ == "__main__":
    # dp.loop.create_task(scheduler(200))
    scheduler.start()
    executor.start_polling(dp, skip_updates=True, on_startup=on_startup)


ошибка:
Job "check (trigger: interval[0:00:20], next run at: 2020-12-21 20:41:50 EET)" raised an exception
Traceback (most recent call last):
  File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\apscheduler\executors\base_py3.py", line 29, in run_coroutine_job
    retval = await job.func(*job.args, **job.kwargs)
  File "E:/main.py", line 75, in check
    count = pn.check_new(pn, db.get_login(message.from_user.id), db.get_password(message.from_user.id))
AttributeError: module 'aiogram.types.message' has no attribute 'from_user'
  • Вопрос задан
  • 45 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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