D
D
Duzive2019-08-25 03:50:32
Python
Duzive, 2019-08-25 03:50:32

Error in the console when writing a message to the bot. How to fix?

I decided to write a bot for VKontakte. Gives an error when writing any message associated with id. Here is the code:

import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType

coding: 'utf-8'

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


token = "мой токен"

vk = vk_api.VkApi(token=token)

longpoll = VkLongPoll(vk)

for event in longpoll.listen():

    if event.type == VkEventType.MESSAGE_NEW:
   
        if event.to_me:
        
            request = event.text
            
            if request == "привет":
                write_msg(event.user_id, "Привет")
            if request == "пока":
                write_msg(event.user_id, "Пока", )
            if request == "как жизнь":
            	write_msg(event.user_id, "Норм, у тебя как?")
            else:
                write_msg(event.user_id, "Не понял вашего ответа...")
print("Бот запущен")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question