Answer the question
In order to leave comments, you need to log in
How to get literal user id via vk_api python?
The bottom line is that I need to make it possible to transfer money to the user in the bot. only now to transfer the money you need his DIGITAL ID which I already got. but it's terribly not convenient, it's easier to write @ and select who you need in the line. so here's how to process what the user has chosen in @ ?
Answer the question
In order to leave comments, you need to log in
An example of a function that returns the user ID by mention(@name, etc.)/link to the page
def get_user(pattern: str) -> int:
if "[id" in pattern:
return int(pattern.split("|")[0].replace("[id", ""))
if "vk.com/" in pattern:
domen = pattern.split("/")[-1]
return vk.users.get(user_ids=domen)
when a user mentions someone, this mention comes in this format:
[id<id>|<text>]
, where id is the user's id, text is the text of the mention
, for example, if you write @id1 (Paul) , it will come in this form:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question