@dp.message_handler(lambda message: message.entities != [] and message.chat.id)
async def delete_messages(message: types.Message):
for entity in message.entities:
if entity.type in ["url", "text_link"]:
await bot.delete_message(message.from_user.id, message.message_id)
break
I tried this, but the message does not want to be deleted, tell me, please, what is the error? I would also be grateful if you tell me how to make an exception. So that links from a specific domain are not deleted (there will be several of them)
@dp.message_handler(content_types=['text'])
async def delete_messages(message: types.Message):
for entity in message.entities:
if entity.type in ["url", "text_link"]:
await message.delete()
This didn’t help either
2
Answers
You should await it
await message.delete()
You should delete the post after the cycle ends: