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 Илья ДьяченкоИлья Дьяченко 11 Answer
Reset to default 0Your 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条)