Home python Python VK API How to get a picture from the user and...

Python VK API How to get a picture from the user and then send it to him?




began to understand python, try various VK-API functions. Now the bot takes any message and sends only a specific picture. It is necessary that he immediately got a picture from the user and sent it to him. Thanks in advance.

import vk_api
from vk_api.longpoll import vklongpoll, vkeventtype
From Activ_Token Import VK_Token
vk_session = vk_api.vkapi (token = vk_token)
session_api = vk_session.get_api ()
LongPoll = VklongPoll (VK_Session)
Def Sender (Text):
  vk_session.method ('Messages.send', {'user_id': ID, 'Message': Text, 'Random_ID': 0})
Def Send_photo (URL):
  vk_session.method ('Messages.send', {'user_id': ID, 'Attachment': URL, 'Random_ID': 0})
For event in longpoll.listen ():
  If event.Type == vkeventtype.message_new:
    If event.to_me:
      MSG = event.text.Lower ()
      id = event.user_id
      Sender (MSG)
      Send_photo ('URL pictures')

Answer 1

def send_photo (peer_id, attachments, random_id = 0):
  vk_session.method ('Messages.send',
    {"peer_id": peer_id, "attachment": attachments, "random_id": random_id})
For Item In Event.Object ['Attachments']:
  If Item ['Type'] == 'Photo':
    send_photo (event.user_id, 'Photo {} _ {}'. Format (Item ['Owner_ID'], Item ['id']))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions