N
N
NoName22813372020-06-18 02:17:43
Python
NoName2281337, 2020-06-18 02:17:43

Working with id with telebot and sqlite3 module, how to do...?

We need a code that writes the ID to the database when the user writes /start . everything is fine, I did it, only if he writes / start again, then his ID will be registered 2 times, and the bot will send him 2+ messages. I've always tried to fix it with for, but something like that, maybe it's necessary with fetchone? Of course, I tried it, it will be enough for him to write down 1 id and that’s it, then he won’t write anything at all ... How to make sure that the id of users is recorded in the sqlite3 database, but at the same time so that it cannot be repeated in any way?

Please, it's very important to me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Renat Ataev, 2020-06-18
@fanepka

There are a lot of videos on this topic.
You just need to check for the presence of the user in the database, and then decide what to do next.

result = cursor.execute(f"SELECT id FROM accounts WHERE uid = {messages.from_user}")
if result == None:
    # Здесь код на добавление, юзера в бд

It is better to do this through a function, and this is an easy example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question