Answer the question
In order to leave comments, you need to log in
How to import handlers from different files?
I don't want the handlers in my bot to be in the same file, as this interferes with the readability of the code and the architecture
. I have such a hierarchy
here
from mess import *
from aiogram.utils import executor
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.redis import RedisStorage2
bot = Bot(token)
storage = RedisStorage2()
dp = Dispatcher(bot, storage=storage)
@dp.message_handler(commands=['start'])
async def p(m: types.Message):
await bot.send_message(m.chat.id, 'hello')
executor.start_polling(dp)
import sys
sys.path.append("..")
from main import dp,types
@dp.message_handler(commands=['stop'])
async def p(m: types.Message):
await bot.send_message(m.chat.id, 'goodbye!')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question