K
K
kadzu22021-04-03 11:45:30
In contact with
kadzu2, 2021-04-03 11:45:30

The bot is running but not responding. What to do?

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from toks import main_token

vk_session = vk_api.VkApi(token = main_token )
session_api = vk_session.get_api()
longpoll = vk_api.longpoll.VkLongPoll(vk_session)

def sender(id, text):
vk_session .method('message.send', {"user_id" : id, 'message' : text, 'random id' : 0})

for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:

msg = event.text.lower()
id = event.user_id

if msg == "Hello":
sender(id, 'Hello to you too')
if msg == "Fedya sucker":
sender(id, ' Himself such')

The code works, there are no errors, but the bot does not read or respond to messages

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
samperirrrrr, 2021-04-03
@samperirrrrr

Remove if event.to_me:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question