S
S
Selita2021-12-25 13:13:25
Python
Selita, 2021-12-25 13:13:25

How to edit posts in aiogram?

@dp.message_handler(commands=['help', 'start'])
async def process_help_command(message: types.Message):
        photo_start = open('img\mcmxl.jpg', 'rb')
        await bot.send_photo(message.from_user.id, photo_start, caption=(MESSAGES['admin_help']), reply_markup=keyboard.startadmin)

startadmin_1 = InlineKeyboardButton(text='Профиль', callback_data="startadmin_1")
startadmin_2 = InlineKeyboardButton(text='Расписание', callback_data="startadmin_2")
startadmin_3 = InlineKeyboardButton(text='Информация', callback_data="startadmin_3")
startadmin_4 = InlineKeyboardButton(text='Настройки', callback_data="startadmin_4")
startadmin_5 = InlineKeyboardButton(text='Статистика', callback_data="startadmin_5")
startadmin_6 = InlineKeyboardButton(text='Удаление', callback_data="startadmin_6")
startadmin_7 = InlineKeyboardButton(text='Аптайм', callback_data="startadmin_7")
startadmin_8 = InlineKeyboardButton(text='Рассылка', callback_data="startadmin_8")
startadmin_9 = InlineKeyboardButton(text='Выкл. бота', callback_data="startadmin_9")
startadmin_10 = InlineKeyboardButton(text='Вкл. бота', callback_data="startadmin_10")
startadmin = InlineKeyboardMarkup().add(startadmin_1, startadmin_2).add(startadmin_3, startadmin_4).add(startadmin_5, startadmin_6).add(startadmin_7, startadmin_8).add(startadmin_9, startadmin_10)

@dp.callback_query_handler(text_contains='startadmin_')
async def menu(call: types.CallbackQuery):
    if call.data and call.data.startswith("startadmin_"):
        code = call.data[-1:]
        if code.isdigit():
            code = int(code)
        if code == 1:
            await call.message.edit_text('Профиль"', parse_mode='Markdown')
        if code == 2:
            await call.message.edit_text("Расписание", parse_mode='Markdown')
        if code == 3:
            await call.message.edit_text('Информация', parse_mode='Markdown')
        if code == 4:
            await call.message.edit_text('Настройки', parse_mode='Markdown')
        if code == 5:
            await call.message.edit_text("Статистика", parse_mode='Markdown')
        if code == 6:
            await call.message.edit_text('Удаление', parse_mode='Markdown')
        if code == 7:
            await call.message.edit_text('Аптайм', parse_mode='Markdown')
        if code == 8:
            await call.message.edit_text("Рассылка", parse_mode='Markdown')
        if code == 9:
            await call.message.edit_text('on', parse_mode='Markdown')
        if code == 10:
            await call.message.edit_text('off', parse_mode='Markdown')
        else:
            await bot.answer_callback_query(call.id)


When you press any button, writes:
aiogram.utils.exceptions.BadRequest: There is no text in the message to edit
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-12-25
@Selita-Marlow

Because you have no text in the original message, and in general this is a photo. You can either send a new message and then edit it. Or try the method edit_caption
https://docs.aiogram.dev/en/latest/telegram/types/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question