Answer the question
In order to leave comments, you need to log in
How to make achievements in asynchronous telegram bot (aiogram)?
I am writing a bot on aiogram with sqlite3 database. This is my first time with async. For example I have:
@tg.message_handler(commands = ['start'])
async def send_welcome(msg: types.Message):
....
@tg.message_handler(content_types = ['text'])
async def sender( msg: types.Message):
....
@tg.callback_query_handler(lambda call: True)
async def callback_inline(call):
....
And here's how I can write a new function that always checks the user's data from the database, so that in if the desired result was achieved, did she send a message about the completed achievement?
Answer the question
In order to leave comments, you need to log in
Roughly speaking, for an asynchronous program, one statement is true: "while you are executing code that is not an await call, the rest of the program is idle."
Each await call (as well as its completion) is an excuse to switch to another task.
So an infinite loop is just:
while True:
await asyncio.sleep(5) #пока текущая корутина спит, остальной бот работает
do_stuff() #пока do_stuff() работает, остальной бот спит
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question