Python. Work with Vk Api

Hello, everyone! I’m a beginner in python 3 and programming in general. I’ve faced the problem in this code:

import vk_api
import time
import random

#I smeard the token
token = bf2************50a6225a1038
vk = vk_api.VkApi(token = token)

#Messages that the bot understands:
user_greeting = ['Hello', 'hello', 'Hi', 'hi', 'Greetings', 'greetings', 'good day', 'Good day', 'excuse me', 'Excuse me', '', '', '',]

#Main cycle:
while True:
        messages = vk.method('messages.getConversations', {'offset': 0, 'count': 20, 'filter': 'unanswered'})
        if messages['count'] >= 1:
            id = messages['items'][0]['last_message']['from_id']
            body = messages['items'][0]['last_message']['text']
            text_message = body.lower()
            text_sorted = text_message.split(' ')
            user_input1 = list(set(text_sorted) & set(user_greeting))
            user_input11 = ' '.join(user_input1)
            if user_input11 in user_greeting:
                vk.method('messages.send', {'peer_id': id, 'message': 'Hello. That conversation absolutely confidential! Only you and andministrators of the group have access to this conversation. Data from the conversation is not distributed anywhere❌🖋', 'random_id': random.randint(1,2147483647)})
                vk.method('messages.send', {'peer_id': id, 'message': "We apologize 🙏. Unfortunately we can't answer you now 🕓. Don't worry, we remember about our question. We will be happy to respond to you as soon as possible😎", 'random_id': random.randint(1,2147483647)})
                vk.method('messages.send', {'peer_id': id, 'message': 'Please write correctly ✍ .', 'random_id': random.randint(1,2147483647)})
    except Exception as E:

When i write message to group, my program disregards user_input11. In any case, it writes the specified message without stopping

I would add print() statements to verify the contents of text_sorted, user_input1 and user_input11. Or use a debugger to examine their contents.

Any of your ‘greetings’ with a space in them will never be recognized by your logic.

  1. Lets say body is “Good Day everyone”
  2. text_message becomes “good day everyone”
  3. text_sorted becomes [“good”, “day”, “everyone”]
  4. user_input1 becomes [] (empty list). This is because user_greeting contains “good day”, and [“good”, “day”] does not match.

I see nothing obviously wrong with your logic regarding any greeting which is a single word.

Ok, but it isn’t main problem.
In your fourth point you said, that the program will write empty list. But! It may be empty list and it may be list with “Hi” for example, but anyway cycle will hold true and bot will write specified messages.

i did it like you, and i looked in console something like this
[‘Good day everyone’]
[‘good’, ‘day’, ‘everyone’]

Whatever it my bot answered me specified messages