C
C
CatRoys2020-06-06 19:00:05
Python
CatRoys, 2020-06-06 19:00:05

How to display usernames from the list?

Hello, I'm making a kind of "table" where information about the current administrators and the creator is displayed, but there was a problem when I wanted to display a name for each ID in this table. How to do it?
Script that displays the table:

if msg == "!админы":
        data1 = session_api.messages.getConversationMembers(peer_id=event.peer_id)
        admin = [x["member_id"] for x in data1["items"] if x.get("is_admin", False)]
        data2 = session_api.messages.getConversationMembers(peer_id=event.peer_id)
        owner = [x["member_id"] for x in data2["items"] if x.get("is_owner", False)]
        owner_info = session_api.users.get(user_ids = owner)
        admin_info = session_api.users.get(user_ids = admin)
        owner_id = owner_info[0]["id"]
        full_name = owner_info[0]['first_name'] +  ' ' + owner_info[0]['last_name']
        send_message(peer_id=event.peer_id,message=" Создатель беседы:\n● @id" + str(owner_id) + "(" + str(full_name) + ")\n Администрация:\n" + str('\n'.join('● @id{}(Пользователь)' for _ in range(len(admin))).format(*admin)))

What to display the bot at the moment:
5edbbd5400ea9537786710.png
Instead of "User" should be names.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2020-06-06
@CatRoys

Then stands instead of the current

str('\n'.join('● @id{}(Пользователь)' for _ in range(len(admin))).format(*admin))

Use directly data from admin_info dictionaries
str('\n'.join(f'● @id{user["id"]}({user["first_name"]} {user["last_name"]})' for user in admin_info))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question