H
H
Harwest2020-10-20 22:14:11
Python
Harwest, 2020-10-20 22:14:11

Error in a simple bot, can you solve it?

In general, this is a questionnaire bot, there is a tree of questions, let's say there are two answers, how are you feeling? -> Norm, not really, and then further clarification of what exactly, but at the 3rd stage an error occurred where the clarification with the Neck Brain, maybe I'm doing it in the wrong function?

import telebot
import json
from telebot import types

token = '' #токен бота
bot = telebot.TeleBot(token)


@bot.message_handler(commands=['start'])
def welcome(message):
        bot.send_message(message.chat.id, 'Здравствуйте вас приветствует бот!')


@bot.message_handler(commands=['text'])
def send_text(message):
    markup = telebot.types.InlineKeyboardMarkup()
    markup.add(telebot.types.InlineKeyboardButton('Хорошо', callback_data=3))
    markup.add(telebot.types.InlineKeyboardButton('Бывало и лучше', callback_data=4))
    bot.send_message(message.chat.id, 'Как вы себя чувствуете?', reply_markup=markup)

@bot.callback_query_handler(func=lambda call: True)
def query_handler(call):

    if call.data == '3':
        answer = 'Счастливого дня!'
    elif call.data == '4':
        answer = 'Что у вас болит?'
        markup = telebot.types.InlineKeyboardMarkup()
        markup.add(telebot.types.InlineKeyboardButton('Голова', callback_data=6))
        markup.add(telebot.types.InlineKeyboardButton('Туловище', callback_data=7))
        markup.add(telebot.types.InlineKeyboardButton('Руки', callback_data=6))
        markup.add(telebot.types.InlineKeyboardButton('Ноги', callback_data=7))
        bot.send_message(call.message.chat.id, 'Что у вас болит', reply_markup=markup)
        bot.send_message(call.message.chat.id, answer)

@bot.callback_query_handler(func=lambda call1: True)
def query_handler1(call1):

    if call1.data == '6':
        answer = 'Уточните'
        markup = telebot.types.InlineKeyboardMarkup()
        markup.add(telebot.types.InlineKeyboardButton('Глаза', callback_data=8))
        markup.add(telebot.types.InlineKeyboardButton('Мозг', callback_data=9))
        markup.add(telebot.types.InlineKeyboardButton('Шея', callback_data=10))
        bot.send_message(call1.message.chat.id, 'Уточните', reply_markup=markup)
        bot.send_message(call1.message.chat.id, answer)

bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-10-20
@eron_63

@bot.callback_query_handler(func=lambda call1: True)
@bot.callback_query_handler(func=lambda call: True)
The two decorators are the same. Handle everything in one

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question