Answer the question
In order to leave comments, you need to log in
Why doesn't bot.callback_query_handler work?
Hello.
I'm trying to create a bot for surveys, but pitfalls immediately pop up, namely:
1. Why does the last function (def call_opros (call)) not respond to a button click? I found the register_next_step_handler method, but it didn't work with it either.
2. How to implement auto-posting to a group, like in Bot controller?
3. How to implement the choice of the right / wrong answer?
I would appreciate any help, thanks in advance.
THE CODE:
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=["start"])
def start(message):
key = types.InlineKeyboardMarkup()
key_start = types.InlineKeyboardButton(text="Создать опрос",callback_data="first")
key.add(key_start)
mess = "Привет, этот бот умеет создавать опросы"
bot.send_message(message.chat.id, mess, reply_markup=key)
@bot.callback_query_handler(func=lambda call:True)
def call_opros(call):
if call.data == "first":
bot.send_message(call.message.chat.id, text="Введите свой вопрос")
@bot.message_handler(content_types=["text"])
def question(message):
key = types.InlineKeyboardMarkup()
key_v = types.InlineKeyboardButton(text="Добавить варианты ответов", callback_data="sec")
key.add(key_v)
mess = "Отлично, Ваш вопрос:\n" + message.text + "\nТеперь добавьте варианты ответов"
msg=bot.send_message(message.chat.id, mess, reply_markup=key)
bot.register_next_step_handler(msg, call_answer)
@bot.callback_query_handler(func=lambda call:True)
def call_answer(call):
if call.data == "sec":
bot.send_message(call.message.chat.id, text="Пришлите свои варианты ответа в столбик")
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
The first one finally worked. The first handler pulls everything onto itself, if I understand correctly.
here is the code
@bot.callback_query_handler(lambda first: first.data=="first")
def call_opros(first):
if first.data == "first":
bot.send_message(first.message.chat.id, text="Введите свой вопрос")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question