H
H
HelpMeeee2021-01-09 21:02:06
Python
HelpMeeee, 2021-01-09 21:02:06

Why doesn't the TELEBOT handler work?

Here is the code, the free_game handler does not work for unknown reasons.
Who can say why?

import telebot
from telebot import types
import random

import SQLighter
import config

bot = telebot.TeleBot(config.token)

@bot.message_handler(commands=["start"])
def repeat_all_messages(message):
    keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
    button_balance = types.KeyboardButton(text="Мои данные")
    button_solo_game = types.KeyboardButton(text="Бесплатная игра")
    button_vip_game = types.KeyboardButton(text="Платная игра")
    keyboard.add(button_vip_game, button_solo_game, button_balance)
    bot.send_message(message.chat.id, "Правила Правила Правила Правила Правила Правила Правила Правила Правила Правила ", reply_markup=keyboard)

skills = 0 #Просто добавил счётчик "скилла" правильных и неправильных ответов

@bot.message_handler(content_types=["text"])
def type_game(message):
    if message.text == "Мои данные":
        bot.send_message(message.chat.id,"Баланс: " + "/n" +
                         "Игр сыграно: " + "/n" +
                         "Правильных ответов: ")
    if message.text == "Бесплатная игра":
        bot.send_message(message.chat.id, "Чтобы начать введите /free_game")

    if message.text == "Платная игра":
        bot.send_message(message.chat.id,"Баланс: "  "/n" 
                         "Игр сыграно: " + "/n" +
                         "Правильных ответов: ")
    #if message.text == '/free_game': #Другой варянт создания комманд
    #	bot.send_message(message.chat.id, "123")

@bot.message_handler(commands=['free_game'])
def free_game(message):
    wrong_answer = 0
    right_answer = SQLighter.answer
    answer_list = [SQLighter.answer, SQLighter.wrong1, SQLighter.wrong2, SQLighter.wrong3]
    random.shuffle(answer_list)
    i = 1
    while i < 16 and wrong_answer == 0:
        keyboard1 = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
        button_answer = types.KeyboardButton(text=SQLighter.answer[i])
        button_wrong1 = types.KeyboardButton(text=SQLighter.wrong1[i])
        button_wrong2 = types.KeyboardButton(text=SQLighter.wrong2[i])
        button_wrong3 = types.KeyboardButton(text=SQLighter.wrong3[i])
        keyboard1.add(button_answer, button_wrong1, button_wrong3, button_wrong2)
        bot.send_message(message.chat.id, SQLighter.question[i], reply_markup=keyboard1)
        if message.text == SQLighter.answer[i]:
            bot.send_message(message.chat.id, "Good")
            i += 1
        else:
            bot.send_message(message.chat.id, "Bad")
            wrong_answer += 1
            i += 1


#print(SQLighter.question)
if __name__ == '__main__':
     bot.infinity_polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-01-09
@twistfire92

move all the code with the free__game handler above, above

@bot.message_handler(content_types=["text"])
def type_game(message):

The /free_game command is also text and it is intercepted by @bot.message_handler(content_types=["text"])
All handlers should be placed from top to bottom from special cases to general ones.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question