V
V
Voprosium2021-08-06 12:42:17
Python
Voprosium, 2021-08-06 12:42:17

The bot is receiving messages, but the handler is not working, what should I do?

Hello! I had a problem, I'm writing a bot on aiogram, and so. The logs say that the message is accepted, but the handler does not work.
I am using the following libraries:

# aiogram            2.14.3
# pip                21.2.2
# aiogram-forms      0.1.1
# aiohttp            3.7.4.post0
# aioschedule        0.5.2
# async-timeout      3.0.1
# asyncio            3.4.3

# main.py
# from handlers import *
from aiogram import executor
from loader import *
from utils.notifier.notify import *


@dp.message_handler(commands=['start'])
async def start_command(message):
    await message.answer("Hello")


async def on_startup(dispatcher: Dispatcher) -> None:
    asyncio.create_task(scheduler())


async def on_shutdown(dispatcher: Dispatcher):
    await dispatcher.storage.close()
    await dispatcher.storage.wait_closed()


if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True, on_shutdown=on_shutdown, on_startup=on_startup)

#loader.py
from aiogram import Bot, Dispatcher
from aiogram.contrib.fsm_storage.files import JSONStorage
from aiogram.contrib.middlewares.logging import LoggingMiddleware

from pathlib import Path
from data.config import BOT_TOKEN

import logging
logging.basicConfig(level=logging.INFO)

bot = Bot(token=BOT_TOKEN)
storage = JSONStorage(Path('states.json'))
dp = Dispatcher(bot, storage=storage)
dp.middleware.setup(LoggingMiddleware())

Initially, the handlers are in a separate file, but they stopped working and I wrote the simplest one in the main file. What to do? Tell me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bl4ckm45k, 2021-08-06
@Bl4ckm45k

from aiogram import types

@dp.message_handler(commands=['start'])
async def start_command(message: types.Message):
    await message.answer("Hello")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question