c# 无法创建 InlineKeyboardButton

标签 c# telegram-bot

我正在创建电报机器人,但无法创建任何 InlineKeyboardButton 对象。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telegram.Bot.Types.InlineKeyboardButtons;

namespace BuildAutomation.Controllers
{
    public class Test
    {
       public TestMethod()
    {
        var none = new InlineKeyboardButton("No", "build|no");
        var yes = "Yes";
        var betaControl = new InlineKeyboardButton(yes, "build|betacontrol");
        var betaNode = new InlineKeyboardButton(yes, "build|betanode");
        var betaBoth = new InlineKeyboardButton(yes, "build|betaboth");

        InlineKeyboardMarkup menu;

        menu = new InlineKeyboardMarkup(new[] { betaBoth, none });
    }
    }
}

我不断收到错误“无法创建抽象类或接口(interface)“InlineKeyboardButton”的实例。我意识到 InlineKeyboardButton 是一个抽象类,但我看到很多创建 InlineKeyboardButton 对象的示例。

我错过了什么吗?

example 1

example 2

example 3

最佳答案

InlineKeyboardButton 的直接实例化在以前的 版本中是正确的。 大约一个月前有一个新的提交,这表明 InlineKeyboardButton 从那时起就被抽象了。您必须改用派生类。 InlineKeyboardUrlButtonInlineKeyboardPayButton等都是从InlineKeyboardButton派生的。 示例的存储库似乎尚未更新。

检查此链接以获取有关上述提交的更多详细信息: https://github.com/TelegramBots/telegram.bot/commit/ddaa8b74e3ab5eab632dbe2e8916c2fe87b114a3

关于c# 无法创建 InlineKeyboardButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45657532/

相关文章:

c# - 根据 LINQ/lambda 中的 Group By 语句计数创建计数

telegram-bot - ctx.updateSubTypes Telgraf 4 的替代品

markdown - Telegram 消息(来自机器人或手动)如何避免数字成为移动设备上的链接?

c# - 如何通过azure函数应用程序从azure表存储中获取所有记录

c# - 如何在一行 C# 3.0 中将 object[] 转换为 List<string>?

c# - 开发人员是否可以通过 "force"系统来防止 "Metro"应用程序在后台异步进程运行时被挂起?

c# - Android 按钮边框颜色渐变

javascript - Telegram 机器人内联键盘标记回调用于 channel 消息

url - 将消息发送到特定机器人的 Telegram URL

telegram-bot - 机器人向 Telegram 用户发送交互式谷歌地图