I used the library aioschedule to send autoscheduled messages to concrete users in telegram bot. The logic is: if the column 'alert' in y_data is 1, the alert will be sent to users from the list GOOD_ID.
The error is:
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-10' coro=<Job.run() done, defined at /opt/anaconda3/lib/python3.8/site-packages/aioschedule/__init__.py:455> exception=TypeError("job() missing 1 required positional argument: 'message'")>
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/aioschedule/__init__.py", line 462, in run
ret = await self.job_func()
TypeError: job() missing 1 required positional argument: 'message'
I don't get how to avoid this mistake, can you help me with that, please?
The code:
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
chat = []
GOOD_ID = [1, 2, 3]
async def job(message: types.Message):
if message.chat.id == chat[0] or message.chat.id in GOOD_ID:
y_data = yesterday_data(df)
if y_data['alert'].values == 1:
await bot.send_message(
message.chat.id,
"Alert!",parse_mode='html', reply_markup=markup
)
else:
await bot.send_message(message.chat.id, "You have no access")
async def scheduler():
aioschedule.every().day.at("15:00").do(job)
# loop = asyncio.get_event_loop()
while True:
await aioschedule.run_pending()
await asyncio.sleep(2)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
task = loop.create_task(scheduler())
executor.start_polling(dp, skip_updates=True)