@motya88

Как отредактировать сообщение используя bot.edit_message_text?

Подскажите, как отредактировать первичное сообщение после ввода его с клавиатруры.
Есть код:
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):

    if call.data[0] == 's':
        global id_msg_bot
        id_msg_bot = call.data
        srh_msg = search_msg.query_with_fetchone(id_msg_bot)
        global msg_grp
        msg_grp = srh_msg[0]

    if call.message:
        if call.data[0] == 's':
            id_msg_bot = call.data
            srh_msg = search_msg.query_with_fetchone(id_msg_bot)
            msg_grp = srh_msg[0]
            msg = bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Шаг 1 из 3." + "\n" + "Введи с клавиатуры коэффициент: " + "\n" * 2 + msg_grp)
            bot.register_next_step_handler(msg, add_koff)


def add_koff(message):
    coefficient = message.text
    srh_msg = search_msg.query_with_fetchone(id_msg_bot)
    msg_grp = srh_msg[0]
    msg_group = msg_grp + '(' + coefficient + ')'
    update.update_msg_coefficient(msg_group, coefficient, id_msg_bot)
    n = types.InlineKeyboardMarkup()
    n1 = types.InlineKeyboardButton(text='П1', callback_data="P1")
    n2 = types.InlineKeyboardButton(text='П2', callback_data="P2")
    n.add(n1, n2)
    bot.edit_message_text(chat_id=message.chat.id, message_id=message.message_id,
                                  text="Шаг 2 из 2." + "\n" + "Выбери действие: " + "\n" * 2 + msg_group,
                          reply_markup=n)


сейчас ругается и говорит [b'{"ok":false,"error_code":400,"description":"Bad Request: message can\'t be edited"}']
  • Вопрос задан
  • 1997 просмотров
Пригласить эксперта
Ответы на вопрос 2
Danya_Violet
@Danya_Violet
CTO/CIO
для Inline
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Выберите:',
                              reply_markup=service_keyboard)
Ответ написан
Комментировать
@Novichek2000
У меня кнопка 1 работает, а кнопка 2 через одно место. Что может быть не так ?((((

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
try:
if call.message:
if call.data == 'good':
bot.send_message(call.message.chat.id, 'Вот и отличненько ')
if call.data == 'bad':
bot.send_message(call.message.chat.id, 'Бывает ')

# удаление встроенных кнопок
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=" Как дела?",
reply_markup=markup3)

# показать оповещение
bot.answer_callback_query(callback_query_id=call.id, show_alert=False,
text="Преобразовано...")

except Exception as e:
print(repr(e))

def callback_inline(call):
try:
if call.message:
if call.data == 'good1':
bot.send_message(call.message.chat.id, 'Бывай...')
if call.data == 'bad1':
bot.send_message(call.message.chat.id, 'Сорян, платки кончились...')

# удаление встроенных кнопок
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Не пиши такое больше",
reply_markup=markup4)

# показать оповещение
bot.answer_callback_query(callback_query_id=call.id, show_alert=False,
text="Преобразовано...!")

except Exception as e:
print(repr(e))

@bot.message_handler(content_types=['text'])
def get_text_messages(message):

if message.text == "Как дела?":

markup3 = types.InlineKeyboardMarkup()
item1 = types.InlineKeyboardButton("Хорошо", callback_data='good')
item2 = types.InlineKeyboardButton("Не очень", callback_data='bad')

markup3.add(item1, item2)

bot.send_message(message.chat.id, text='Отлично, сам(-а) как?', reply_markup=markup3)

if message.text == "Люблю тебя":

markup4 = types.InlineKeyboardMarkup()
item1 = types.InlineKeyboardButton("Успокоиться", callback_data='good1')
item2 = types.InlineKeyboardButton("Вытереть слезки", callback_data='bad1')

markup4.add(item1, item2)

bot.send_message(message.chat.id, text='Выбрать действие:', reply_markup=markup4)

bot.polling(none_stop=True, interval=0)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы