Answer the question
In order to leave comments, you need to log in
python vk_api code not working?
There is a code:
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk_sess = vk_api.VkApi(token='')
api_sess = vk_sess.get_api()
longpool = VkBotLongPoll(vk_sess, group_id)
def send(text):
api_sess.method('message.send', {'chat_id': event.chat_id, 'message': text, 'random_id': 0})
for event in longpool.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
msg = event.text.lower()
if msg == 'привет':
send('Мяу-привет')
Answer the question
In order to leave comments, you need to log in
def send(text):
'chat_id': event.chat_id
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
vk_session = vk_api.VkApi(token='your_group_token')
vk = vk_session.get_api()
longpoll = VkBotLongPoll(vk_session, 'your_group_id')
for event in longpoll.listen():
msg = event.text.lower()
if msg == 'привет':
if event.type == VkBotEventType.MESSAGE_NEW:
vk.messages.send(
user_id=event.chat_id,
random_id=get_random_id(),
message='Мяу-привет'
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question