A
A
Alexey Fobius2021-03-02 21:57:59
Python
Alexey Fobius, 2021-03-02 21:57:59

Checking events in event.raw vk api?

How to check the entry of a person into a conversation?

for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
         if event.raw['object']['message']['action']['type'] == 'chat_invite_user':

gives an error message
TypeError: list indices must be integers or slices, not str


I understand that something must be an integer here, but I don’t understand what it’s all about (we are talking about list indexes, but the question is: which list?)

I also found an answer to a similar question on Habré, specifically:

if 'action' in event.raw['object']:
                if 'chat_invite_user' in event.raw['object']['action']['type']:


the error is still the same

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Fobius, 2021-03-03
@phobious

In short, until you find the answer yourself, no one will help, with a fresh mind I thought and got
this code, then think for yourself what is responsible for what, documentation to help you

info_message = vk.messages.getById(message_ids=event.message_id)

            invite = info_message['items'][0]['action']["type"]
            invite_id = info_message['items'][0]['action']['member_id']

            invite_get=vk.users.get(user_ids = (invite_id))  
            invite_get=invite_get[0]
            first_name_invite_users=invite_get['first_name']
            last_name_invite_users=invite_get['last_name']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question