Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

strange behavior of a telegram bot on python

$
0
0

I am writing a telegram bot on python and aiogram3. And a strange problem appeared. At some point, the bot stopped responding to the command. The logs contain the following message INFO:aiogram.event:Update id=798588584 is not handled. Duration 0 ms by bot id=6724341043.There were no changes in the code. I also tried to find a solution in ethernet, but couldn't find anything. Then I just created a new project. And copied all the code from the old one. The result has not changed . But at some point after the next launch of the bot in a new project, it began to respond to commands. I checked the old project again, and the bot still did not respond to commands there. I will provide the code below, it is identical in two projects.file bot_create

from aiogram import Bot, Dispatcherfrom aiogram.fsm.storage.memory import MemoryStoragebot = Bot('6724341043:AAEK51DMwxmFqy8rBTThNvJ43xq9AG-Gaq4')dp = Dispatcher(storage=MemoryStorage())

file bot_start

import asyncioimport loggingimport sysfrom bot_create import dp, botfrom data_base import sql_dbasync def main():    sql_db.sql_db_start()    await dp.start_polling(bot, skip_updates=True)if __name__ == '__main__':    logging.basicConfig(level=logging.INFO, stream=sys.stdout)    asyncio.run(main())

file handlers admin

import asyncioimport loggingimport sysfrom os import getenvfrom aiogram import Bot, Dispatcher, Router, typesfrom aiogram.dispatcher import routerfrom aiogram.enums import ParseModefrom aiogram.filters import CommandStartfrom aiogram.fsm.context import FSMContextfrom aiogram.fsm.state import StatesGroup, Statefrom aiogram.types import Messagefrom aiogram.utils.markdown import hboldfrom bot_create import dpfrom aiogram.filters.command import Commandfrom data_base import sql_dbimport bot_textclass FSMAdmin(StatesGroup):    question = State()    answer = State()    admins = State()@dp.message(Command(bot_text.start_moderator.lower()))async def start_command(message: types.Message, state: FSMContext):    await state.set_state(FSMAdmin.admins)    await message.answer(bot_text.start_admin)@dp.message(FSMAdmin.admins)async def start_admin(message: types.Message, state: FSMContext):    if message.text in bot_text.key_world:        context_date = str(message.from_user.id)        await sql_db.sql_add_admin(context_date)        await message.answer("доступразрешен")    else:        await message.answer("ошибкавкодовомслове")    await state.clear()@dp.message(Command(bot_text.add_question_command.lower()))async def add_question(message: types.Message, state: FSMContext):    admins = await sql_db.is_admin()    if str(message.from_user.id) in ((admin[0]) for admin in admins):        await message.answer(bot_text.add_question)        await state.set_state(FSMAdmin.question)    else:        print(str(message.from_user.id))        print(admins)        await message.answer("no")@dp.message(FSMAdmin.question)async def note_question(message: types.Message, state: FSMContext):    await state.update_data(question=message.text)    await message.answer(bot_text.add_answer)    await state.set_state(FSMAdmin.answer)@dp.message(FSMAdmin.answer)async def add_answer(message: types.Message, state: FSMContext):    count = await sql_db.count()    data = await state.get_data()    data["answer"] = message.text    data["number"] = count + 1    print(data)    await sql_db.sql_add_question(data)    await message.answer(bot_text.save_question)    await state.clear()

I couldn't find anything on this issue.


Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>