Answer the question
In order to leave comments, you need to log in
How to get the name of the invited user?
Hello! I don’t understand how to get the name of the invited person to the conversation, the bot welcomes only the one who invited. Code snippet:
if event.type == VkBotEventType.MESSAGE_NEW:
from_id = event.obj['from_id']
peer_id = event.obj['peer_id']
message = event.obj['text'].lower()
sender_name = list(filter(lambda name: name['id'] == event.obj.from_id, [name for name in vk.messages.getConversationMembers(peer_id=event.obj.peer_id, fields='profiles')['profiles']]))[0]
last_and_first_name = str(sender_name['first_name']) + ' ' + str(sender_name['last_name'])
first_name = str(sender_name['first_name'])
last_name = str(sender_name['last_name'])
if 'action' in event.raw['object']:
if 'chat_invite_user_by_invitelink' in event.raw['object']['action']['type']:
mess = 'Привет ' + f'[id{event.obj.from_id}|{first_name}]' + '!'
send_message(peer_id, mess)
if 'chat_invite_user' in event.raw['object']['action']['type']:
mess = 'Привет ' + f'[id{event.obj.from_id}|{member_name}]'
send_message(peer_id, mess)
Answer the question
In order to leave comments, you need to log in
Try this method for example!
response = api.users.get(access_token = token, user_ids = id)
first_name = response[0]['first_name']
print(first_name)
token = vk_api.VkApi(token = "token ")
vk = token.get_api()
user_id = id
vks = vk.users.get(user_id = user_id)
is_closed = vks[0]['is_closed']
print(is_closed)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question