Home>

Created a database of nicknames and VK id's associated with them. When I write something in a VK conversation on my own behalf, then everything is fine, my nickname and id are displayed. When someone else writes, outputs None

nicks= sqlite3.connect('niki23.db')
cur= nicks.cursor()
nicks.execute('CREATE TABLE IF NOT EXISTS {}(nickname PRIMARY KEY, vk PRIMARY KEY)'.format('niki'))
nicks.commit()
nick00= cur.execute(f'SELECT * FROM niki WHERE vk== {user_id}').fetchone()
nicks.commit()
print(nick00, "-input")
nick01= cur.execute(f'SELECT nickname FROM niki WHERE vk== {user_id}').fetchone()
nicks.commit()
print(nick01, "-vk nick")
sam_nick= nick01
#nick01= " ".join(map(str, nick00))
#sam_nick0= nick01.split()
if "/nick"== msg and nick01 is not None:
        vk_session.method('messages.send', {'chat_id':id, "message": f"You are @id{user_id} ({sam_nick})", 'random_id' : 0})

In order to get the nickname and id of the user who wrote the chat bot, the library has built-in functions. I would recommend using them

fedor.chernolutsky2022-02-12 10:48:47

If we talk specifically about your problem, then you need to check the user_id variable at the moment when another user writes, and also what will return the execution of the sql query for this id outside the chat bot, etc. Perhaps the id is not in the database or the value of the user_id variable is incorrect at the time the message was sent by another user

fedor.chernolutsky2022-02-12 10:58:00