S
S
Skauyt2021-05-06 15:52:24
Python
Skauyt, 2021-05-06 15:52:24

How to check for presence in a conversation?

Found the following function:

def check_kf(peer_id:int) -> list:
  authorize.method("messages.getConversationMembers", {
        "peer_id": peer_id
    })["items"]

As I understand it, it allows you to check whether there is a person in the conversation or not. Using it, I tried to create another function:
def add_v_besedy(sender,uid):
  uid = reseived_message[10:19]
  user_id = uid
  if uid in check_kf(3):
    write_message(sender,'text')
  else:
    write_message(sender,'as')

If the user id(int) in the conversation with peer_id = 3, then the send message function is executed.
When I run the code, I get an error on the line ( if uid in check_kf(3): ):
TypeError: argument of type 'NoneType' is not iterable
How can I fix this? I created a function so that if the user, when invited to the conversation, is already in it, some answer is written

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2021-05-06
@Skauyt

To start

in conversation with peer_id = 3

All conversation IDs start at 2000000000, -user id=3Then
, messages.getConversationMembers returns a list of dictionaries in items, so you ca if uid in check_kf(3):n't check through.
https://vk.com/dev/messages.getConversationMembers
And on top of all this, the function check_kfdoes not return anything, so it needs to be completed
def check_kf(peer_id:int) -> list:
  return authorize.method("messages.getConversationMembers", {
        "peer_id": peer_id
    })["items"]

Something like this
def add_v_besedy(sender,uid):
  uid = reseived_message[10:19]
  user_id = uid
  users = check_kf(2000000003)
  for user in users:
    if user['member_id']  == user_id:
      write_message(sender,'text')
      return
  write_message(sender,'as')

Well, there's reseived_message[10:19]clearly something wrong.

C
CleanyBoom, 2021-05-06
​​@CleanyBoom

In fact, you simply do not return anything from the function, and this is an error, because you cannot check for the presence of a user in the list if this list does not exist

def check_kf(peer_id:int) -> list:
  return authorize.method("messages.getConversationMembers", {
        "peer_id": peer_id
    })["items"]

S
sergeyfilippov4, 2021-05-07
@sergeyfilippov4

1) Get a list of participants
2) Check if the required ID is in the list

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question