c# - 如何在 NetTelegramBot KeybrardMarkup 中放置多行?
问题描述
我正在用 c# 制作一个电报机器人。我想读一些名字(不超过 20 个,你可能会更少)并将它们作为键盘标记提供给用户。对于一维数组,它们全部放在一行中,并且不可读。我想用 5 个名称制作 4 行,所以我尝试了一个 4x5 数组。但我得到这个错误
错误 CS0029 无法将类型“NetTelegramBotApi.Types.KeyboardButton[ , ]”隐式转换为“NetTelegramBotApi.Types.KeyboardButton[][]”
if (text == "/lista")
{
// Read a text file line by line.
listapz = System.IO.File.ReadAllLines("listapz.txt");
string selezione = "Seleziona il paziente:";
int i = 0;
int x = 0;
int y = 0;
var arrays = new KeyboardButton[4,5];
for (i = 0; i < listapz.Length; i++)
{
y = i / 5;
x = i - (y * 5);
arrays[y,x] = new KeyboardButton("$" + (i + 1) + " " + listapz[i]);
selezione += "\n$" + (i + 1) + " " + listapz[i] + "";
}
var keyb = new ReplyKeyboardMarkup()
{
Keyboard = arrays,
OneTimeKeyboard = true,
ResizeKeyboard = true
};
var reqAction = new SendMessage(update.Message.Chat.Id, selezione) { ReplyMarkup = keyb };
bot.MakeRequestAsync(reqAction).Wait();
Console.WriteLine(reqAction);
continue;
}
有什么解决办法吗?
解决方案
您可以为每一行创建新的一维数组然后
keyb.row(first_array) //you need get only values in python it will like keyb.row(*array)
keyb.row(second_array) //and so on
并将所有键盘合二为一reply_markup=keyb
推荐阅读
- python - 如何聚类标签(在多标签分类问题中)大多一起出现在一个类中
- node.js - full-ICU 在传递 --icu-data-dir 节点选项时有效,但在使用 NODE_ICU_DATA 环境变量时无效
- react-native - pod install failed on macOS Big sur
- html - How to a collapse other menus when click on radio buttons in bootstrap
- python - How to lessen the python path?
- javascript - How can I link to the 'select' option within my form
- reactjs - Error: Response not successful: Received status code 400 @apollo/client and GraphQl
- python - ModuleNotFoundError: No module named 'Practise' - Although this folder exists
- azure - 用于路由到终结点的 Azure 流量管理器自定义标头
- reactjs - 使用 React JS 进行复选框验证