Reputation: 73
I am using Python-Telegram-Bot API to create a bot. I get people's userID and username when they start the bot.
The userID doesn't change ever but the username can be changed by the user any time.
So I have usernames and UserIDs, and I receive another username - I wish to figure out whether that username is of someone already in the existing list or not.
Basically need to find out username from userID or if there's any other way I'm open to it.
Upvotes: 4
Views: 16662
Reputation: 780
thats why you always process messages using the users' IDs
but to answer your question, you can either get the user's username directly using the user
object, for example update.message.from_user.username
or update.effective_user.username
or use bot.getchat(chat_id)
to get an user object of a certain chat (which could be an user's private chat
Upvotes: 6