J
J
Just1n2019-05-05 14:03:53
Python
Just1n, 2019-05-05 14:03:53

Why is the bot not responding to the message?

The bot receives the message, sees it, but does not respond to it.

from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import vk_api

vk = vk_api.VkApi(token='тут мой токен')
vk._auth_token()
vk.get_api()

longpoll = VkBotLongPoll(vk, id моей группы)

while True:
    for event in longpoll.listen():
        if event.type == VkBotEventType.MESSAGE_NEW:
            if event.object.peer_id == event.object.from_id:
                print('Сообщение получено 1')
                if event.object.text.lower() == "Привет":
                    print('Сообщение получено 2')
                    vk.messages.send(peer_id=event.object.peer_id, message='Привет!', random_id=0)

The terminal displays "Message received 1", but "Message received 2" does not.
Most likely an error in this piece, but how to solve it? UPD from 04/27/2020: I was very stupid when I asked this question, I am very ashamed, sorry
if event.object.text.lower() == "Привет":

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Damir Konkov, 2019-05-05
@Just1n

I'll be a wag, but most likely, the lower() function returns hello , not Hello .
Therefore your condition is always false.
Replace string "Привет"with string "привет"
Well, learn how to debug your code, it's a good skill.
Print the contents of the value event.object.text.lower()before the last condition is met.
To see what value is in this variable.
print(event.object.text.lower())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question