Answer the question
In order to leave comments, you need to log in
It says that I have one column, and I don’t understand how to make two, and bot.polling() also gives an error, what should I do?
import telebot
import sqlite3
from telebot import types
import random
bot = telebot.TeleBot('')
@bot.message_handler(commands=['reg'])
def start(message):
connect = sqlite3.connect('ddlcusers.db')
cursor = connect.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS login_id (
id INT PRIMARY KEY,
cash INT NOT NULL
)''')
connect.commit()
#id
usersid = message.from_user.id
checkid = message.from_user.id
cursor.execute(f'SELECT id FROM login_id WHERE id = {checkid}')
if cursor.fetchone() is None:
cursor.execute('INSERT INTO login_id VALUES (?, ?)', (usersid, 0))
connect.commit()
bot.send_message(message.from_user.id, "Вы успешно были добавлены в базу данных.")
else:
bot.send_message(message.from_user.id, 'Такой пользователь уже есть в базе данных бота.')
bot.send_sticker(message.from_user.id, 'CAACAgIAAxkBAAECln1g8aeuFxR5g0bpgKlsQcrwHggrRAAC-BIAAkXUMEvqmAABi9b6IkogBA')
#delete user bd
@bot.message_handler(commands=['delete'])
def delete(message):
bot.send_message(message.from_user.id, 'Ваш айди с базы данных был успешно удалён.')
connect = sqlite3.connect('ddlcusers.db')
cursor = connect.cursor()
#delete id
people_id = message.from_user.id
cursor.execute(f'DELETE FROM login_id WHERE id = {checkid}')
connect.commit()
@bot.message_handler(commands=['menu'])
def menu(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
item1 = types.KeyboardButton('Рандомное число')
item2 = types.KeyboardButton('Добавить деньги')
markup.add(item1)
bot.send_message(message.from_user.id, f'Привет!', reply_markup = markup)
@bot.message_handler(content_types=['text'])
def bot_message(message):
if message.chat.type == 'private':
if message.text == "Рандомное число":
bot.send_message(message.chat.id, "Ваше чилсо: " + str(random.randint(0, 1000)))
#elif message.text == "Добавить деньги":
bot.polling()
Answer the question
In order to leave comments, you need to log in
CREATE TABLE IF NOT EXISTS login_id (write in one line, your second column has not been created
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question