Answer the question
In order to leave comments, you need to log in
How to add the user's first and last name to the logs?
There is a code:
import vk_api.vk_api
import random
import requests
import re
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
# Настройки
group_id = id # Цифровой ID группы
admins = [1, 2, 3]
mytoken = "token"
vk = vk_api.VkApi(token = mytoken)
vkapi = vk.get_api()
lp = VkBotLongPoll(vk, group_id, wait = 5)
for event in lp.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
username = event.object.from_id
msg = event.object.text
print("Пользователь: " + str(username) + "\nСообщение: " + msg)
Answer the question
In order to leave comments, you need to log in
users.get method, code:
_user = vkapi.users.get(user_ids=event.object.user_id)
print(f'Имя: {_user[0]["first_name"]}, Фамилия: {_user[0]["last_name"]}')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question