如何使用 Telebot 模块在 bot 窗口中创建一个内嵌按钮,如果点击该按钮将与组中的“创建投票"按钮非常相似? [英] How to use telebot module to create an inline button in bot window, which if clicked will work very similar to 'Create poll' button found in groups?

查看:44
本文介绍了如何使用 Telebot 模块在 bot 窗口中创建一个内嵌按钮,如果点击该按钮将与组中的“创建投票"按钮非常相似?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 python 比较陌生,我正在尝试使用 Telebot 创建一个电报机器人,它将创建一个类似测验的游戏,每个用户也可以创建自己的类似测验的游戏.在用户创建此测验的逐步过程中,有一次,我需要他们向我发送民意调查,就像他们在组中创建新民意调查一样.但是在电报机器人中没有创建轮询按钮,因为这些按钮通常在组中而不是在一对一聊天中找到.所以我需要创建一个内联键盘按钮,点击后会让用户创建一个投票并将其发送给机器人.我已经浏览了 github 中的文档,但找不到任何有用的内容.

I am relatively new to python and I am trying to create a telegram bot using telebot, which will create a quiz-like game, and each user can create their own quiz-like game also. During the step by step process of creating this quiz by the user, at one point, I need them to send me a poll, just like how they create a new poll in a group. But there is no create poll button inside telegram bot as these buttons are generally found in groups and not in one-one chats. So I need to create an inline keyboard button, which upon clicking will let the users create a poll and send it to the bot. I have gone through the documentation in github and couldn't find anything useful for this.

这个类似的东西是由电报自己的Quizbot"实现的.为清楚起见,我将附上该机器人的屏幕截图.请帮助我确定如何在我的机器人中实现它.

This similar thing is implemented by telegram's own "Quizbot". I'll attach the screenshots from that bot for clarity. Please help me identify how to implement it in my bot.

如果创建问题"按钮被点击:

If 'Create question" button is clicked:

我是 Python 和编码的菜鸟,所以请帮我解决这个问题.

I am a noob to python and coding, so please help me with this problem.

如果我使用电报桌面而不是电话,我可以向机器人发送投票.我想知道如何在手机中启用它.

edit: I can send a poll to the bot if I am using telegram desktop and not from the phone. I want to know how to enable to use it in the phone.

推荐答案

通过使用 Telebot,我们可以做到这一点.这也让我们有机会通过手机应用创建投票.

By using telebot we can do this. This gives us the opportunity to create poll from phone apps also.

import telebot
from telebot.types import ReplyKeyboardMarkup,KeyboardButton, 
                          KeyboardButtonPollType,ReplyKeyboardRemove

bot=telebot.Telebot(token='your bot token')
poll_markup=ReplyKeyboardMarkup(one_time_keyboard=True) 
poll_markup.add(KeyboardButton('send me a poll',
                request_poll=KeyboardButtonPollType(type='quiz')))
#from my experience, only quiz type and regular type polls can be send.

remove_board=ReplyKeyboardRemove()
bot.send_message(chat_id,text,reply_markup=poll_markup)
#some other code here

#this can be used to remove the replykeyboard when you no longer need it.
bot.send_message(chat_id,text,reply_markup=remove_board)

                                          

这篇关于如何使用 Telebot 模块在 bot 窗口中创建一个内嵌按钮,如果点击该按钮将与组中的“创建投票"按钮非常相似?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆