c# 无法创建 InlineKeyboardButton
c# Cannot create InlineKeyboardButton
我正在创建电报机器人,但无法创建任何 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 });
}
}
}
我不断收到错误消息“无法创建抽象 class 或接口 'InlineKeyboardButton' 的实例。我意识到 InlineKeyboardButton 是一个抽象 class,但我看到很多示例创建 InlineKeyboardButton.
的对象
我是不是漏掉了什么?
InlineKeyboardButton
的直接实例化在 以前的 版本中是正确的。
大约一个月前有一个新的提交,这表明 InlineKeyboardButton
从那时起就被抽象了。您必须改用派生 类。 InlineKeyboardUrlButton
、InlineKeyboardPayButton
等都是从InlineKeyboardButton
派生出来的。
示例的存储库似乎尚未更新。
检查此 link 以获取有关上述提交的更多详细信息:
https://github.com/TelegramBots/telegram.bot/commit/ddaa8b74e3ab5eab632dbe2e8916c2fe87b114a3
在示例中使用 InlineKeyboardCallbackButt
,InlineKeyboardCallbackButton("Yes", "CallBackData")
而不是 InlineKeyboardButton("Yes", "CallbackData")
您无法创建新的抽象实例 class。所以使用下面的示例
var KeyboardButons = new InlineKeyboardButton[][]
{
new InlineKeyboardButton[]
{
InlineKeyboardButton.WithCallbackData("سفارش", callbackQueryData) ,
InlineKeyboardButton.WithCallbackData("بازگشت", "return")
}
};
var replyMarkup = new InlineKeyboardMarkup()
{
InlineKeyboard = KeyboardButons
};
我正在创建电报机器人,但无法创建任何 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 });
}
}
}
我不断收到错误消息“无法创建抽象 class 或接口 'InlineKeyboardButton' 的实例。我意识到 InlineKeyboardButton 是一个抽象 class,但我看到很多示例创建 InlineKeyboardButton.
的对象我是不是漏掉了什么?
InlineKeyboardButton
的直接实例化在 以前的 版本中是正确的。
大约一个月前有一个新的提交,这表明 InlineKeyboardButton
从那时起就被抽象了。您必须改用派生 类。 InlineKeyboardUrlButton
、InlineKeyboardPayButton
等都是从InlineKeyboardButton
派生出来的。
示例的存储库似乎尚未更新。
检查此 link 以获取有关上述提交的更多详细信息: https://github.com/TelegramBots/telegram.bot/commit/ddaa8b74e3ab5eab632dbe2e8916c2fe87b114a3
在示例中使用 InlineKeyboardCallbackButt
,InlineKeyboardCallbackButton("Yes", "CallBackData")
而不是 InlineKeyboardButton("Yes", "CallbackData")
您无法创建新的抽象实例 class。所以使用下面的示例
var KeyboardButons = new InlineKeyboardButton[][]
{
new InlineKeyboardButton[]
{
InlineKeyboardButton.WithCallbackData("سفارش", callbackQueryData) ,
InlineKeyboardButton.WithCallbackData("بازگشت", "return")
}
};
var replyMarkup = new InlineKeyboardMarkup()
{
InlineKeyboard = KeyboardButons
};