Подскажите, как исправить Message to delete not found, после нажатия на кнопку удалить, текст удаляется, но секунд через 30, появляется вот такая ошибка.
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-9' coro=<Dispatcher._process_polling_updates() done, defined at F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\dispatcher\dispatcher.py:407> exception=MessageToDeleteNotFound('Message to delete not found')>
Traceback (most recent call last):
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "F:/1samoe_nuzhnoe/Py__Python/Telegram/PyCharm/Tg_aiogram_ru/chat_ti1_t2.py", line 49, in handler_text
await send.delete()
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\types\message.py", line 2986, in delete
return await self.bot.delete_message(self.chat.id, self.message_id)
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\bot\bot.py", line 2823, in delete_message
return await self.request(api.Methods.DELETE_MESSAGE, payload)
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\bot\base.py", line 231, in request
return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\bot\api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\bot\api.py", line 115, in check_result
exceptions.BadRequest.detect(description)
File "F:\1samoe_nuzhnoe\Py__Python\Telegram\PyCharm\Tg_aiogram_ru\aiogram\utils\exceptions.py", line 140, in detect
raise err(cls.text or description)
aiogram.utils.exceptions.MessageToDeleteNotFound: Message to delete not found
Весь код
#from time import time, gmtime, strftime, sleep
import aiogram
import logging
import math
import os
import time
import asyncio
import aiohttp
import random
from time import sleep
from time import time
from aiogram import Bot, Dispatcher, executor, types
from aiogram.types import CallbackQuery, ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardButton, ChatMember
from aiogram.types import InlineQuery, \
InputTextMessageContent, InlineQueryResultArticle
from aiogram.contrib.middlewares.logging import LoggingMiddleware
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import FSMContext
from asyncio import sleep
from contextlib import suppress
from aiogram.utils.exceptions import (MessageToEditNotFound, MessageCantBeEdited, MessageCantBeDeleted, MessageToDeleteNotFound)
#from data import config
API_TOKEN = 'moi_token'
logging.basicConfig(level=logging.INFO)
bot = Bot(token=API_TOKEN)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
dp.middleware.setup(LoggingMiddleware())
btn_send_delete = InlineKeyboardButton('Удалить', callback_data='message_delete')
btn_send_markup = InlineKeyboardMarkup().add(btn_send_delete)
@dp.callback_query_handler(lambda c: c.data == 'message_delete')
async def dell_callback(callback: types.CallbackQuery):
await callback.answer('Удалено')
await bot.delete_message(chat_id=callback.message.chat.id, message_id=callback.message.message_id)
@dp.message_handler(content_types=["text"])
async def handler_text(message):
menu = types.InlineKeyboardMarkup(row_width=1)
item2 = types.InlineKeyboardButton(" Прочитать", callback_data='exit_to_prochitat')
menu.add(item2)
for i in range(1):
send = await message.reply("Здравствуйте, {0.first_name}. \n\nОбязательно нажмите кнопку <b>->Прочитать.</b>".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html', reply_markup=menu)
await asyncio.sleep(30)
await send.delete()
break
@dp.callback_query_handler(lambda call: True)
async def podpishis_callback(call: types.CallbackQuery):
chat_id = call.message.chat.id
message_id = call.message.message_id
if call.message:
if call.data == 'exit_to_prochitat':
send = await bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="\n\nЗдесь весь текст".format(call.message.from_user, bot.get_me()), parse_mode='html', reply_markup=btn_send_markup)
await asyncio.sleep(20)
await send.delete()
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)