I
I
Ivan64712021-11-27 17:02:30
Python
Ivan6471, 2021-11-27 17:02:30

How to delete bot message when clicking on inline button?

I want to implement deleting a bot message when clicking on the inline button in a public chat, but an error occurs:

raise err(cls.text or description)
aiogram.utils.exceptions.MessageToDeleteNotFound: Message to delete not found


Here is the code:
@dp.message_handler(content_types=['new_chat_members'])
async def on_user_joined(message: types.Message):
    await message.reply('текст', reply_markup=urlkb)

urlkb = InlineKeyboardMarkup(row_width=1).add(InlineKeyboardButton(text='принять', callback_data='test'))

@dp.callback_query_handler(text="test")
async def test_call(message: types.Message):
    await bot.delete_message(message.from_user.id, message.message.message_id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ambal245, 2021-12-12
@ambal245

maybe there is an error in this line

await bot.delete_message(message.from_user.id, message.message.message_id)

And it needs to
await bot.delete_message(message.from.chat_id, message.message.message_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question