Answer the question
In order to leave comments, you need to log in
How to find user ID in Telegram having username?
For example, I want to make a command: Marry @username_one @username_two, in order for everything to work correctly in the future, I need to take the IDs of these two people and put them in columns in MySQL. How can this be done correctly? (Do not offer to do it through the ID immediately showing their user, I need it through @username, I also want to use it in other commands, the ID will certainly not work there). Thank you in advance.
Answer the question
In order to leave comments, you need to log in
I used Gram.JS connected to the bot and using ResolveUsername I pull the id from the username.
By telegram, no way.
You can keep a table matching id - username. And from there to take the data.
Also, we must not forget about the possibility of changing the username. So you need to make it possible to update this table when changing username.
PS: the username of the user can be obtained by:
1) Receiving a message from him
2) Sending him a message
Therefore, it is best to look at his username when sending each message to the user and if it has changed, then update the correspondence in the table.
Or if the user has not written for a long time, then send him a message, look at his username and immediately delete the message
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question