Answer the question
In order to leave comments, you need to log in
How to make a bot in a VK conversation download a photo and send it back?
I wrote a simple bot for a conversation in VK that can send photos by url
Now I want to write a bot that can download a photo that the user throws off (writes the right word and attaches a photo), the bot downloads the photo and sends it back to the conversation with the words here you go
How can I do this, where to read, except for the vk api documentation, what to see
Help please
In the code, the bot sends a photo of the MDK avatar
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from config import main_token
from PIL import Image
vk_session = vk_api.VkApi(token = main_token)
vk = vk_session.get_api()
longpoll = VkLongPoll(vk_session)
def sender(id, text):
vk.messages.send(chat_id = id, message = text, random_id = 0)
def send_photo(id, url):
vk.messages.send(chat_id = id, attachment = url, random_id = 0)
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.from_chat:
msg = event.text.lower()
id = event.chat_id
if msg == 'morgen':
send_photo(id, 'photo-57846937_457307562')
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