C
C
chocolated2022-03-16 21:32:17
Python
chocolated, 2022-03-16 21:32:17

How to make the bot display the username and not none?

If you write directly to the bot, then it gives out the username of the one who wrote to him, and when added to the group chat, it starts issuing @none
62322b9d53c05246071943.png
62322ba9ca3e9448676361.png

a = [f"На сегодня @{message.chat.username} лучший в мире", f"Оууу теперь @{message.chat.username} микро челик"]
b = random.choice(a)
bot.send_message(message.chat.id, b)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
A9FM, 2022-03-16
@chocolated

I advise you to change the library altogether, there are many disadvantages.
with regards to the problem, try it
usernames = message.from_user.username
(May not work, because I myself am sitting on pyrogram)

P
PavelMos, 2022-03-16
@PavelMos

Check in the program itself, for example, through debugging, which in the case of a group chat is written in message.chat.username.
None most likely means that there is an empty value, that is, something should have been written to this variable, but it was not written.

F
Forraz, 2022-03-16
@Forraz

Maybe the one who tested the bot in the group does not have a username? You can not mention the user, but simply specify the first and last names through first_name and last_name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question