B
B
Baga2021-05-17 19:39:25
Python
Baga, 2021-05-17 19:39:25

It is necessary for the bot to brother the username through the id. That's what happened, what needs to be fixed?

elif message.text == '123' or message.text == '1245':
m = message.from_user.username(user_id = 1616641932)
bot.reply_to(message, 'Yes, @'+ m + ' is he?')

Error:
m = message.from_user.username(user_id = 1616641932)
TypeError: 'str' object is not callable

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Altry, 2021-05-18
@Baga12324

message.from_user.username is not a method, no arguments are given to it. It will give you the username of the person whose message was triggered by this handler.

name = message.from_user.username #или
name = message.from_user.full_name

By the same principle, you can get the user's language:
lang = message.from_user.locale

K
Kadabrov, 2021-05-17
@Kadabrov

What is the name of the module?
Most likely username already contains string data, and you are trying to call it as a function by opening brackets after username, which is what the error tells you
String data cannot be called as a function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question