2017-03-31 68 views
0

我想用c#創建一個帶有電報機器人的鍵盤,但我不能,當我添加鍵盤時顯示錯誤。無法在C中使用NetTelegramBotApi創建鍵盤#

的NuGet PAKAGE是:安裝,包裝NetTelegramBotApi

這是我自己的代碼。

namespace TelegramBotConsole 
{ 
    class Program 
    { 
     // Keyboards 
     public static ReplyKeyboardMarkup MainMenu; 
     // Telegram Bot Token. 
     private static string BotToken="Bot_Api"; 
     static void Main(string[] args) 
     { 
      // Add The Keuboards 
      MainMenu = new ReplyKeyboardMarkup 
      { 
       Keyboard = new[] { new[] { "Amuzeshha" }, new[] { "Rahnama", "About" } } 
      }; 
     // Running The Bot. 
     Task.Run(() => RunBot()); 
     // Read The Log of Bot. 
     Console.ReadLine(); 
    } 
    // Create Bot. 
    public static async Task RunBot() 
    { 
     var Bot = new TelegramBot(BotToken); 
     var Me = await Bot.MakeRequestAsync(new GetMe()); 
     // Geting The Infromation of Bot. 
     Console.WriteLine("Username Is : {0}", Me.Username); 
     Console.WriteLine("My ID Is : {0}", Me.Id); 
     Console.WriteLine("My Name Is : {0}", Me.FirstName); 
     long offset = 0; 
     while (true) 
     { 
      var updates = await Bot.MakeRequestAsync(new GetUpdates() { Offset = offset }); 
      foreach (var update in updates) 
      { 
       offset = update.UpdateId + 1; 
       var text = update.Message.Text; 
       if (text == "/start") 
        { 
         var Req = new SendMessage(update.Message.Chat.Id, "You Should Send Picture") { ReplyMarkup = MainMenu }; 
         await Bot.MakeRequestAsync(Req); 
         continue; 
        } 
       if(update.Message.Photo == null) 
       { 
        var Req = new SendMessage(update.Message.Chat.Id, "Please Send A Picture") { ReplyMarkup = MainMenu }; 
        await Bot.MakeRequestAsync(Req); 
        continue; 
       } 
       else 
       { 
        var Req = new SendMessage(update.Message.Chat.Id, "Thanks") { ReplyMarkup = MainMenu}; 
        await Bot.MakeRequestAsync(Req); 
        continue; 
       } 
      } 
     } 
    } 
} 

此代碼不起作用。

MainMenu = new ReplyKeyboardMarkup 
     { 
      Keyboard = new[] { new[] { "Amuzeshha" }, new[] { "Rahnama", "About" } } 
     }; 

問題在哪裏?

和這個錯誤的屏幕截圖。 enter image description here

+0

錯誤消息告訴您使用正確的類型。 – stuartd

回答

1
Keyboard = new[] { 
    new[] { 
     new KeyboardButton("Amouzeshha"), 
     new KeyboardButton("Help"), 
     new KeyboardButton("About") 
    } 
} 
+1

儘管此代碼可能會回答這個問題,但提供有關爲何和/或代碼如何回答問題的其他上下文會提高其長期價值。 –