Answer the question
In order to leave comments, you need to log in
Why doesn't the bot show the button on the keyboard?
Hello! In programming, a beginner, there was a problem when writing a bot, namely a problem with the operation of a button.
I wanted the user to be added to the database after the start command and the button to continue the dialogue with the bot would fly out, but the button does not corny crash on the keyboard, or the button crashes, but the user is not added to the database. What to do?
Here is part of the code:
import sqlite3
import telebot
from telebot import *
bot = telebot.TeleBot("2042542684:AAF1wOuI8mt7DQIb859TkPa7bHHBk6YohPk")
conn = sqlite3.connect('db/database.db', check_same_thread=False)
cursor = conn.cursor()
def db_table_val(user_id: int, user_name: str, user_surname: str, username: str):
cursor.execute('INSERT OR IGNORE INTO test (user_id, user_name, user_surname, username) VALUES (?, ?, ?, ?)', (user_id, user_name, user_surname, username))
conn.commit()
@bot.message_handler (commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Welcome')
keyboard = telebot.types.ReplyKeyboardMarkup(True)
keyboard.row('Get Horoscope')
us_id = message.from_user.id
us_name = message.from_user.first_name
us_sname = message.from_user.last_name
username = message.from_user.username
db_table_val(user_id=us_id, user_name=us_name, user_surname=us_sname, username=username)
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
if message.text.lower() == 'hello':
bot.send_message(message.chat.id, 'Hi!')
bot. polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question