Answer the question
In order to leave comments, you need to log in
SQLite3 is added id, username, etc. user Telegram (aiogram). How to make sure that the data is added not from the message, but from the members of the group?
def post_sql_query(sql_query):
with sqlite3.connect('WrnDtb.db') as connection:
cursor = connection.cursor()
try:
cursor.execute(sql_query)
except Error:
pass
result = cursor.fetchall()
return result
def create_tables():
users_query = '''CREATE TABLE IF NOT EXISTS USERS
(user_id INTEGER PRIMARY KEY NOT NULL,
username TEXT,
first_name TEXT,
last_name TEXT,
reg_date TEXT);'''
post_sql_query(users_query)
def register_user(user, username, first_name, last_name):
user_check_query = f'SELECT * FROM USERS WHERE user_id = {user};'
user_check_data = post_sql_query(user_check_query)
if not user_check_data:
insert_to_db_query = f'INSERT INTO USERS (user_id, username, first_name, last_name, reg_date) VALUES ({user}, "{username}", "{first_name}", "{last_name}", "{ctime()}");'
post_sql_query(insert_to_db_query )
create_tables()
@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
await bot.send_message(message.from_user.id, f'Welcome {message.from_user.first_name}' )
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