Answer the question
In order to leave comments, you need to log in
How can a bot not write some lines?
I have a sqlite3 database where the user's numbers are stored (money; bank; box; lvl; xp) The bot displays the numbers with this code:
@dp.message_handler(commands=['number'])
async def number(message: types.Message):
conn = sqlite3.connect('db.db')
cur = conn.cursor()
user_id = message.from_user.id
result = cur.execute("SELECT * FROM users WHERE user_id = ?", (user_id, )).fetchone()
money = result[5]
bank = result[6]
box = result[7]
lvl = result[8]
xp = result[9]
money1 = (f"У вас money: {money}")
bank1 = (f"У вас bank: {bank}")
box1 = (f"У вас box: {box}")
lvl1 = (f"У вас lvl: {lvl}")
xp1 = (f"У вас xp: {xp}")
await message.reply(f"{money1} {bank1} {box1} {lvl1} {xp1}")
await message.reply(f"{money1} {bank1} {lvl1} ")
Answer the question
In order to leave comments, you need to log in
Make a routine, at least.
def format_non_zero(items):
message_list = []
for format, value in items:
if value != 0:
message_list.append(format.format(value))
return message_list
msg_parts = format_non_zero([ #каждый элемент списка - отдельное значение+его формат. Порядок тот же.
("У вас money: {0}", money), #обрати внимание на строку формата!
("У вас bank: {0}", bank),
("У вас brain: {0}", brain),
]) #функция вернёт список строк
await message.reply('\n'.join(msg_parts)) #соединяем строки перед отправкой.
read something on the basics of programming. At least a school textbook
if(result == 0):
await message.reply(f"{money1} {bank1} {lvl1} ") Like
this?
Well, something like that.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question