python - INFO:aiogram.event:Update id=??????????? is not handled - Stack Overflow

I have a big telegram bot project. Today, he suddenly stopped showing signs of life. I don't know

I have a big telegram bot project. Today, he suddenly stopped showing signs of life. I don't know exactly what changes led to this result. The problem is that the handler has stopped responding to commands.

INFO:aiogram.dispatcher:Start polling
INFO:aiogram.dispatcher:Run polling for bot ...
INFO:aiogram.event:Update id=????? is not handled. Duration 0 ms by bot id=?????

I've reduced the code to basic, but it still doesn't work, what could be the reason?

main.py

import logging
import asyncio
from aiogram.types import Message, FSInputFile
from aiogram.filters import CommandStart
from aiogram import Bot, Dispatcher


bot = Bot(token="79127??????????????????fXTNyc")
dp = Dispatcher()


async def main():
    await dp.start_polling(bot)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    asyncio.run(main())


logo_photo = FSInputFile('212649.png')


@dp.message(CommandStart())
async def cmd_start(message: Message):
    await message.answer_photo(photo=logo_photo, caption='текст')

PS: the id and token are hidden intentionally

I have a big telegram bot project. Today, he suddenly stopped showing signs of life. I don't know exactly what changes led to this result. The problem is that the handler has stopped responding to commands.

INFO:aiogram.dispatcher:Start polling
INFO:aiogram.dispatcher:Run polling for bot ...
INFO:aiogram.event:Update id=????? is not handled. Duration 0 ms by bot id=?????

I've reduced the code to basic, but it still doesn't work, what could be the reason?

main.py

import logging
import asyncio
from aiogram.types import Message, FSInputFile
from aiogram.filters import CommandStart
from aiogram import Bot, Dispatcher


bot = Bot(token="79127??????????????????fXTNyc")
dp = Dispatcher()


async def main():
    await dp.start_polling(bot)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    asyncio.run(main())


logo_photo = FSInputFile('212649.png')


@dp.message(CommandStart())
async def cmd_start(message: Message):
    await message.answer_photo(photo=logo_photo, caption='текст')

PS: the id and token are hidden intentionally

Share Improve this question edited Nov 17, 2024 at 12:20 Maurice Meyer 18.1k4 gold badges35 silver badges52 bronze badges asked Nov 17, 2024 at 12:18 Илья ДьяченкоИлья Дьяченко 1
Add a comment  | 

1 Answer 1

Reset to default 0

Your function cmd_start just cannot be handled because when your bot started polling, the cmd_start wasn't declared. You should place the cmd_start before you run the main function. You should have the code like this at least:

import logging
import asyncio
from aiogram.types import Message, FSInputFile
from aiogram.filters import CommandStart
from aiogram import Bot, Dispatcher


bot = Bot(token="79127??????????????????fXTNyc")
dp = Dispatcher()


logo_photo = FSInputFile('212649.png')

# the function is declared before entering the main working loop
@dp.message(CommandStart())
async def cmd_start(message: Message):
    await message.answer_photo(photo=logo_photo, caption='текст')

async def main():
    await dp.start_polling(bot)

# all handlers are declared and now you can run the bot
if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    asyncio.run(main())

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745635879a4637388.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信