Linked Questions

Popular Questions

I'm researching aiogram module for Telegram bots. Handlers for messages from Telegram are decorated with @dp..... wrappers where dp = Dispatcher(). All examples in docs are about one file code. So, it works as follows:

dp = Dispatcher(bot)
@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):

So here no problem - we initialize dp and then use it in handlers functions. What if we separate code to different files - how to pass dp object from main file to other modules? I mean we can't pass dp as an argument to handlers functions because it is used not inside the function but to describe (wrap) it before usage. I believe this should be kind of a regular task but for some reason didn't find an answer.

Should we use some kind of functions constructors? So that we pass dp to function-constructor that then creates another function wrapping it in the moment of creation?

Related Questions