Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
import vk_api from vk_api import VkUpload from vk_api.longpoll import VkLongPoll, VkEventType from vk_api.utils import get_random_id authorize = vk_api.VkApi(token = token) longpoll = VkLongPoll(authorize) image = 'C:/test/yes.jpg' upload = VkUpload(authorize) def write_message(sender, message): authorize.method('messages.send', {'user_id': sender, 'message': message, 'random_id': get_random_id(), 'attachment' : ','.join(attachments)}) while True: for event in longpoll.listen(): if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text: reseived_message = event.text sender = event.user_id attachments = [] upload_image = upload.photo_messages(photos=image[0]) attachments.append('photo{}_{}'.format(upload_image['owner_id'], upload_image['id'])) if reseived_message == 'начать': write_message(sender, 'Добрый день') else: write_message(sender, 'Не понял')