How to create InlineKeyboardMarkup this example?

偶尔善良 提交于 2019-12-10 11:49:55

问题


I want to create a Button that when Click on button user go to the group telegram. but cann`t

using NetTelegramBotApi; // last verion

class Program
    {
        private static string Token = "......";
       // private static InlineKeyboardMarkup Menu1;
    }


  public static async Task RunBot()
        {


 // var keyboardInlineMenu = new InlineKeyboardButton[20][];

.....
.....
....
....

if (text == "/start")
  {


// keyboardInlineMenu  = new InlineKeyboardButton () {


InlineKeyboardButton[][] buttons = new InlineKeyboardButton[2][];
buttons[0][0] = new InlineKeyboardButton(){Text = " Go to group  ", Url = "https://api.telegram.org/......" CallbackData = "Some Callback Data"};
InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup() { InlineKeyboard = buttons  };

Error (in line buttons[0][0] )

Object reference not set to an instance of an object.


回答1:


 var newMsg = new SendMessage(update.Message.Chat.Id, "msg")
                            {
                                ReplyMarkup = new InlineKeyboardMarkup()
                                    {
                                        InlineKeyboard = new[] 
        {
            new[] { new InlineKeyboardButton{Text="A",Url = "http://www.A.com/"}, new InlineKeyboardButton(){Text="B",Url = "http://www.B.com/"} }

        }
                                    }
                            };

                            await bot.MakeRequestAsync(newMsg);
                            continue;


来源:https://stackoverflow.com/questions/41533074/how-to-create-inlinekeyboardmarkup-this-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!