M
M
maxkrikov992020-01-18 13:01:36
Python
maxkrikov99, 2020-01-18 13:01:36

Why is the phyton bot not responding to the conversation?

I coded a bot in python, it works great in PM, but for some reason it does not work in a conversation. Here is the code:

import vk_api
from vk_api import VkApi
import requests
import random
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType

def write_msg(rand_int, user_id, message):
    vk.method('messages.send', {'user_id': user_id,'message': message, 'random_id': rand_int})



token = ""

vk = VkApi(token=token)

longpoll = VkBotLongPoll(vk, "149920968")

print("[i]  -  Бот успешно запущен.")

while True:
    for event in longpoll.listen():
     if event.type == VkBotEventType.MESSAGE_NEW and event.to_me and event.text:
        if event.text == 'бот':
             randint = random.randint(100000000, 900000000)
             chat_id = vk.method('messages.getConversations')
             chat_id = chat_id['items']
             print(chat_id)
             write_msg(randint, event.chat_id, "Привет")
        time.sleep(5)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2020-01-18
@maxkrikov99

1. Use a tag for the code For the code
2. The bot needs permission to read messages in the conversation
3. Here's how to properly use the bot, official github https://github.com/python273/vk_api/blob/master/ex...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question