我有一个大型电报机器人项目。今天,他突然没有了生命迹象。我不知道到底是什么变化导致了这个结果。问题是处理程序已停止响应命令。
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=?????
我已经将代码精简到基本,但仍然不起作用,可能是什么原因?
主.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:id和token是故意隐藏的
您的函数 cmd_start 无法处理,因为当您的机器人开始轮询时,未声明 cmd_start 。您应该在运行 main 函数之前放置 cmd_start 。你至少应该有这样的代码:
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())