M
M
Mag1str2021-06-21 17:07:29
Python
Mag1str, 2021-06-21 17:07:29

How to display the username correctly?

There is such a code, it displays not a username but an id with a link.
60d09cf57db09403986812.png

game = get_blackjack_game(game_id)
        p1_result, p2_result = game[-4], game[-3]
        win_amount = ((game[-2] * 2) - (game[-2] * 2) / 100 * float(config('game_percent')))
        bank = f" Выиграл: {win_amount}₽"
        bank_amount = game[-2] * 2
        p1_username = (await bot.get_chat(game[1]))["username"]
        p2_username = (await bot.get_chat(game[2]))["username"]
        if p1_result > p2_result and p1_result < 22:
            update_balance(game[1], win_amount)
            winner = f" Победитель: <a href='t.me//{p1_username}'>{game[1]}</a>"
            winner_id = game[1]
            loser_id = game[2]
        elif p2_result > p1_result and p2_result < 22:
            update_balance(game[2], win_amount)
            winner = f" Победитель: <a href='t.me//{p2_username}'>{game[2]}</a>"
            winner_id = game[2]
            loser_id = game[1]
        elif p2_result == p1_result and p2_result < 22:
            update_balance(game[1], game[-2])
            update_balance(game[2], game[-2])
            bank = f" Выиграл: 0₽"
            winner = f" Победитель: НИЧЬЯ"
            winner_id = 0
            loser_id = 0


There is a code that correctly outputs:
await bot.send_message(game[1],
                                           f"✅ <a href='tg://user?id={call.message.chat.username}'>{call.message.chat.first_name} </a>"
                                           f"присоединился к игре #<code>{game_id}</code> на сумму <code>{game[-2]}</code>₽ , ожидайте свой ход.")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question