2017-03-31 70 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

尽管此代码可能会回答这个问题,但提供有关为何和/或代码如何回答问题的其他上下文会提高其长期价值。 –