英文:
How to make ReplyKeyboardMarkup with telegram-bot-api Golang
问题
我找到的唯一信息是2015年的一个关闭的线程,其中涉及到库的问题。代码片段如下:
itemsSel := [][]string{}
itemsSel = append(itemsSel, []string{item1.Caption, item2.Caption, item3.Caption})
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "选择项目")
msg.ReplyMarkup = &tgbotapi.ReplyKeyboardMarkup{
Keyboard: itemsSel,
ResizeKeyboard: true,
OneTimeKeyboard: false,
Selective: false,
}
log.Println(msg.ReplyMarkup)
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
在https://core.telegram.org/bots/api#replykeyboardmarkup上有一些关于tgbotapi.ReplyKeyboardMarkup对象的描述,但是我不知道如何创建这个对象。帮帮我吧 :3
英文:
Only one information I found is closed thread from 2015 with problem in library. There was a piece of code
itemsSel := [][]string{}
itemsSel = append(itemsSel, []string{item1.Caption, item2.Caption, item3.Caption})
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Select item")
msg.ReplyMarkup = &tgbotapi.ReplyKeyboardMarkup{
Keyboard: itemsSel,
ResizeKeyboard: true,
OneTimeKeyboard: false,
Selective: false,
}
log.Println(msg.ReplyMarkup)
msg.ReplyToMessageID = update.Message.MessageID
bot.Send(msg)
There is some description of tgbotapi.ReplyKeyboardMarkup object, but there is a matrix of KeyboardButton objects as it is written on https://core.telegram.org/bots/api#replykeyboardmarkup. How to make this object, I don't know. Help me :3
答案1
得分: 1
你好,这是我是如何做的:
-
在代码中定义你的回复键盘,包括所有的行和按钮
var itemsSel = tgbotapi.NewReplyKeyboard( tgbotapi.NewKeyboardButtonRow( tgbotapi.NewKeyboardButton("按钮1"), tgbotapi.NewKeyboardButton("按钮2")), )
-
然后定义你的消息配置
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "主菜单")
-
将你的回复键盘分配给消息的回复标记,像这样
msg.ReplyMarkup = mainMenu
-
发送消息
bot.Send(msg)
我是从一个乌克兰的 YouTuber 那里学到的。这是视频链接:https://www.youtube.com/watch?v=yJkzK1-fLf4
英文:
Hello this is how I did it
-
Define your reply keyboard with all its rows and buttons in rows
var itemsSel = tgbotapi.NewReplyKeyboard( tgbotapi.NewKeyboardButtonRow( tgbotapi.NewKeyboardButton("button1"), tgbotapi.NewKeyboardButton("button2")), )
-
then you define your message config
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "Main Menu")
-
assign your Reply Keyboard to the Message Reply Markup like this
msg.ReplyMarkup = mainMenu
-
Send it
bot.Send(msg)
I learned all that from some Ukrainian youtuber
Here is the video https://www.youtube.com/watch?v=yJkzK1-fLf4
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论