gpt4 book ai didi

c# - 在 C# Telegram Bots 中使用键盘编辑短信

转载 作者:太空宇宙 更新时间:2023-11-03 14:59:09 25 4
gpt4 key购买 nike

我使用内联键盘发送了一条消息(使用 SendTextMessageAsyncInlineKeyboardMarkup)。当我第一次尝试编辑时 - EditMessageTextAsync(使用 InlineKeyboardMarkup)方法工作正常,但是当我第二次尝试修改此消息时,我得到了

Bad Request: message is not modified.

代码:

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);

异常:

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()

最佳答案

如果您想编辑键盘,请使用EditMessageReplyMarkupAsync

否则,如果您想编辑消息内容键盘,请使用EditMessageTextAsync

异常示例:

// 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);

关于c# - 在 C# Telegram Bots 中使用键盘编辑短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47134866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com