Reputation: 67
I sent a message with inline keyboard (with SendTextMessageAsync
and InlineKeyboardMarkup
).
When I tried to edit at the first time - EditMessageTextAsync
(with InlineKeyboardMarkup
) method working fine, but when I trying to modify this message at the second time I got
Bad Request: message is not modified.
The code:
response = string.Format("...");
rkm = new InlineKeyboardMarkup();
//...
rkm.InlineKeyboard = new[]
{
new[] { InlineKeyboardButton.WithCallbackData("...", "/filters") }
};
await client.EditMessageTextAsync(update.CallbackQuery.Message.Chat.Id, update.CallbackQuery.Message.MessageId, response, replyMarkup: rkm);
The exception:
Bad Request: message is not modified at Telegram.Bot.TelegramBotClient.d__109`1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at AutoSearch.Notifications.Sources.Telegram.TelegramBot.d__7.MoveNext()
Upvotes: 2
Views: 3585
Reputation: 613
If you want to edit the keyboard Only use EditMessageReplyMarkupAsync
Otherwise if you want to edit the message content and the keyboard use EditMessageTextAsync
Exception Example:
// Defining Message data
string text = "<b>Hello World</b>";
int myChatId = 142536987; // Some chat
InlineKeyboardButton btn = InlineKeyboardButton.WithCallbackData("DoSomething");
// Sending message
Message msg = await SendTextMessageAsync(myChatId, text, ParseMode.Html, true, false, 0, btn);
// New keyboard for message
InlineKeyboardButton newBtn = InlineKeyboardButton.WithCallbackData("Return");
// DON'T DO THAT:
// EXCEPTION!
//>>> MESSAGE IS NOT MODIFIDE!
// You must change the text...
msg = await EditTextMessageAsync(msg.Chat, msg.MessageId, text, true, newBtn);
// True way to edit the keyboard without text
msg = await EditMessageReplyMarkup(msg.Chat, msg.MessageId, newBtn);
Upvotes: 1
Reputation: 7975
You can ignore this sort of error, it just “not modified” because of new text in same with old one.
If you want to solve this error, just add time stamp like “Last Modified: 6:57 PM”.
Upvotes: 0