Делаю команду /dashboard. Столкнулся с тем что выводит только ID, но не имя.
Код в main.py
@dp.message_handler(commands = ["dashboard", "топ", "дешбоард", "дешборд"], commands_prefix='./')
async def top(message):
db_rep.cursor.execute(f"SELECT id, rep FROM users ORDER BY rep DESC LIMIT 10")
leadermsg = "*Топ експертов*:\n\n"
fetchleader = db_rep.cursor.fetchall()
for i in fetchleader:
leadermsg += f"{fetchleader.index(i) + 1}| {i[0]}: {i[1]} exp.\n"
await message.reply(leadermsg)
Код из db_rep.py
import sqlite3
con = sqlite3.connect('reputation.db')
cursor = con.cursor()
def CreateDB():
cursor = con.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS users(name TEXT, id INT, rep INT)")
con.commit()
def UpdateValue(val_name, new_val, id):
for row in cursor.execute(f"SELECT {val_name} FROM users where id={id}"):
new = row[0]+new_val
cursor.execute(f"UPDATE users SET {val_name}={new} where id={id}")
con.commit()
def InsertValue(name, id):
cursor.execute(f'INSERT INTO users VALUES ("{name}", {id}, 0)')
con.commit()