首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何用c#在电报机器人中创建键盘?

如何用c#在电报机器人中创建键盘?
EN

Stack Overflow用户
提问于 2017-01-31 12:34:16
回答 1查看 267关注 0票数 0

我是电报机器人的新手,我想为我的bot创建自定义键盘,为此目的编写以下代码:

代码语言:javascript
运行
复制
var rkm = new ReplyKeyboardMarkup();

rkm.Keyboard =
    new KeyboardButton[][]
    {
        new KeyboardButton[]
        {
            new KeyboardButton("1-1"),
            new KeyboardButton("1-2")
        },

        new KeyboardButton[]
        {
            new KeyboardButton("2")
        },
        new KeyboardButton[]
        {
            new KeyboardButton("3-1"),
            new KeyboardButton("3-2"),
            new KeyboardButton("3-3")
        }
    };

WebRequest req = WebRequest.Create("https://api.telegram.org/bot" + "282189232:AAGdsdsdsdVOrsxy2rzU75QUAnWL_F2vo" + "/sendMessage?chat_id=" + chat_id + "&text=" + message + "&reply_markup=" + rkm);
req.UseDefaultCredentials = true;
var result = req.GetResponse();
req.Abort();

但是当我在这行中运行这段代码时:

代码语言:javascript
运行
复制
var result = req.GetResponse();

获取此错误:

远程服务器返回一个错误:(400)坏请求。

我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2017-02-26 11:31:13

正如建议的那样,使用MrRoundRobin库。下面是你要怎么做的:

代码语言:javascript
运行
复制
var keyboard = new ReplyKeyboardMarkup(new [] {
    new [] // 1st row
    {
        new KeyboardButton("1"),
        new KeyboardButton("2"),
    },
    new [] // 2nd row
    {
        new KeyboardButton("3"),
        new KeyboardButton("4"),
    }
});

await Bot.SendTextMessageAsync(message.Chat.Id, "Choose", replyMarkup: keyboard);;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41957750

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档