V
V
Valde01832022-03-12 02:02:59
Python
Valde0183, 2022-03-12 02:02:59

Checking for different commands?

Hello! I'm coming to you with a question. I don't understand how to do if, elif checks for different words in this bottle. tried if message.text, nothing works.
Here is the code that logs the user into the database.
Or should I do every time --> @bp.on.message(text="balance") ? further the logic of the bot.
The code:

@bp.on.private_message(text="начать")
async def reg_handler(message: Message):
    xx = open("data.txt","r", encoding = 'utf-8')
    x = xx.read()
    xx.close()
    if(str(message.from_id) in x):
        users = read_bd()
    else:
        new_user(message.from_id)
        save_bd(users)
        return "Вы были успешно зарегистрированы! ✔️"
    for user in users:
        if user.id == message.from_id:
            if message.from_id == "баланс":
                return f" Ваш баланс: {user.money} монет!"
    save_bd(users)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wearant, 2022-03-12
@Valde0183

if message.from_id == "баланс":
It's not
from_id - it's the sender's id.
and you need to use this

if "баланс" == message.text: 
    return f" Ваш баланс: {user.money} монет!"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question