F
F
fodiche2021-08-08 17:09:39
Python
fodiche, 2021-08-08 17:09:39

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

2 answer(s)
W
WolfInChains, 2021-08-08
@fodich

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)

S
Stockholm Syndrome, 2021-08-08
@StockholmSyndrome

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 question

Ask a Question

731 491 924 answers to any question