Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- import sqlite3
- # bot
- bot = telebot.TeleBot("token")
- @bot.message_handler(commands=['add'])
- def add(message):
- connect = sqlite3.connect('users.db')
- cursor = connect.cursor()
- cursor.execute("""CREATE TABLE IF NOT EXISTS user_id(
- id INTEGER,
- info TEXT,
- username TEXT
- )""")
- connect.commit()
- # add values in fields
- text = message.text.replace('/add ', '', 1)
- user_id = [message.chat.id, text, message.chat.username]
- cursor.execute("INSERT INTO user_id(id, info, username) VALUES(?, ?, ?);", user_id)
- connect.commit()
- @bot.message_handler(commands=['get'])
- def get(message):
- connect = sqlite3.connect('users.db')
- cursor = connect.cursor()
- cursor.execute("SELECT info FROM user_id WHERE info='%s'")
- print(cursor.fetchall())
- if cursor.fetchall() is None:
- bot.send_message(message.chat.id, "Вы должны зарегистрироваться с помощью команды /add")
- else:
- bot.send_message(message.text, '//', message.chat.id)
- connect.commit()
- @bot.message_handler(commands=['delete'])
- def delete(message):
- pass
- # polling
- bot.polling()
Add Comment
Please, Sign In to add comment