R
R
Roma2021-01-15 20:24:09
Python
Roma, 2021-01-15 20:24:09

How to get python user id?

I want to get the user id in VK
Bot based on Long Polling

I tried many times, but I can’t
Please tell me how to do it, I beg you :[

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sergeyfilippov4, 2021-01-16
@sergeyfilippov4

event.message.from_id - sender ID here

S
samperirrrrr, 2021-01-17
@samperirrrrr

import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType

vk_session = vk_api.VkApi(token = 'цензура')
longpoll = VkBotLongPoll(vk_session, цензура)

def sender(id, text):
  vk_session.method('messages.send', {'chat_id' : id, 'message' : text, 'random_id' : 0})

for event in longpoll.listen():
  if event.type == VkBotEventType.MESSAGE_NEW:
    if event.from_chat:
      id = event.chat_id
      
  msg = event.object.message['text'].lower()
      elif msg == 'айди': 
    sender(id, f'{event.obj.from_id}')

S
soremix, 2021-01-22
@SoreMix

studio code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question