W
W
WazzzUp10022019-12-07 18:18:17
Python
WazzzUp1002, 2019-12-07 18:18:17

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)

As far as I understand, through the output of the event event, you need to catch the member_id and display it. But I don't understand how to get member_id.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Baron Grafovich, 2020-01-26
@FlooJack

Try this method for example!

response = api.users.get(access_token = token, user_ids = id)
first_name = response[0]['first_name']
print(first_name)

Or like this one!
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 question

Ask a Question

731 491 924 answers to any question