W
W
WolfInChains2020-05-11 18:14:07
Python
WolfInChains, 2020-05-11 18:14:07

How to fix list indices must be integers or slices, not str?

user[0]['first_name'] + " " + user[0]['last_name'] already tried

if event.object.text == "онлайн":
                       members = vk.method("messages.getConversationMembers",
                                           {
                                               "peer_id": event.object.peer_id,
                                           }
                                           )['profiles']
                       useronline = members['online']
                       if useronline == 1:
                           user = vk.method("users.get",
                                           {
                                               "peer_id": event.object.peer_id,
                                           }
                                           )['response']
                           userid = user['id']
                           full_name = user['first_name'] + " " + user['last_name']
                           online = " " + f'[id{userid}|{full_name}]' + "\n"
                           vk.method("messages.send",
                                     {
                                         "chat_id": event.object.peer_id - 2000000000,
                                         "message": " Сейчас в сети: " + f'\n{online}',
                                         "random_id": random.randint(1, 2147483647)
                                     })

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-05-11
@hottabxp

Before add , there may be nothing there, or another word, or the word "Online" with a capital letter.
if event.object.text == "онлайн":
print(event.object.text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question