首页 > 解决方案 > 如何在 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;
                    }

有什么解决办法吗?

标签: c#telegram-bot

解决方案


您可以为每一行创建新的一维数组然后

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


推荐阅读