H
H
HelpMeeee2021-01-09 01:20:18
Python
HelpMeeee, 2021-01-09 01:20:18

Why are the buttons not showing in the telegram bot?

Hello!
I write a bot in python, a telebot. I ran into a problem that for some reason the buttons are not displayed in the bot.
Who can understand because of what such a problem, there are no errors?
The bot.py code itself -

import telebot
from telebot import types
import random

import SQLighter
import config

bot = telebot.TeleBot(config.token)


def count_rows():
    """ Считаем количество строк """
    result = cursor.execute('SELECT * FROM questions').fetchall()
    return len(result)

@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, SQLighter.question)
    	bot.register_next_step_handler(message, free_game)#Перенаправил на функцию free_game
i = 1
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)

    while i < 16 and wrong_answer == 0:
        keyboard = types.ReplyKeyboardMarkup(row_width=1, resize_keyboard=True)
        button_answer = types.KeyboardButton(text=answer_list[0])
        button_wrong1 = types.KeyboardButton(text=answer_list[1])
        button_wrong2 = types.KeyboardButton(text=f"{answer_list[2]}")
        button_wrong3 = types.KeyboardButton(text=answer_list[3])
        keyboard.add(button_answer, button_wrong1, button_wrong3, button_wrong2)
        bot.send_message(message.chat.id, SQLighter.question, reply_markup=keyboard)
        if message.text == right_answer:
            bot.send_message(message.chat.id, "Good")
        else:
            bot.send_message(message.chat.id, "Bad")
            wrong_answer += 1
        i += 1

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


SQLlighter.py code -
import sqlite3
import config
import random
import bot

db = sqlite3.connect(config.database_name)
cursor = db.cursor()

def count_rows():
    """ Считаем количество строк """
    result = cursor.execute('SELECT * FROM questions').fetchall()
    return len(result)

i = bot.i
all = cursor.execute('SELECT * FROM questions').fetchall()
question = cursor.execute('SELECT question FROM questions WHERE id = ?', (i,)).fetchall()[0]
answer = cursor.execute('SELECT answer FROM questions WHERE id = ?', (i,)).fetchall()[0]
wrong1 = cursor.execute('SELECT wrong1 FROM questions WHERE id = ?', (i,)).fetchall()[0]
wrong2 = cursor.execute('SELECT wrong2 FROM questions WHERE id = ?', (i,)).fetchall()[0]
wrong3 = cursor.execute('SELECT wrong3 FROM questions WHERE id = ?', (i,)).fetchall()[0]
i += 1

print(question)
print(answer)
print(wrong1)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question