Answer the question
In order to leave comments, you need to log in
How to connect a python bot to a VK conversation?
I am writing a bot. Works as it should in a private conversation, but I need it to work in a third party chat. I have already done everything: I allowed the community to be added to conversations, added a bot to the conversation, made it an admin. But nothing happens
import random
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from intbot import IntBot
def write_msg(user_id, message):
vk.method('messages.send', {'user_id': user_id, 'message': message, 'random_id': random.randint(0, 2048)})
token = "__________________________________________________________________________"
vk = vk_api.VkApi(token=token)
longpoll = VkLongPoll(vk,group_id)
vk_api = vk.get_api()
for event in longpoll.listen():
for event in longpoll.listen ( ):
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
print ('New message:')
print (f'For me by: {event.user_id}', end='')
bot = IntBot (event.user_id)
write_msg (event.user_id, bot.new_message (event.text))
print ('Text: ', event.text)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question