L
L
L1MO2021-10-31 15:02:18
Python
L1MO, 2021-10-31 15:02:18

How to send a post with an image in VK?

There is a code that sends messages to the group that are sent to the bot.

import vk_api
import time
import aiogram
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor

TOKEN = 'Токен Бота'
admin_id = 'Чат айди'

bot = Bot(token=TOKEN)
dp = Dispatcher(bot)

group_id = '-айдигруппы'

token_vk = 'Токен вконтакте'

vk_session = vk_api.VkApi(token=token_vk)
vk = vk_session.get_api()

@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
  await bot.send_message(message.chat.id, f' Здравствуйте {message.from_user.username} \n бот успешно работает.')
  await bot.send_message(message.chat.id, f' Введите любое сообщения, для постинга в группе.')

#Отправка сообщений из бота в группу
@dp.message_handler(content_types=['text'])
async def process_start_command(message: types.Message):
  posting = vk.wall.post(owner_id=group_id, message=f'{message.text}')


if __name__ == '__main__':
    executor.start_polling(dp)


How to make it so that you can upload a picture to telegram and send it along with the text to a group (in one message) or just a picture, I've been struggling for 3 hours, but there is no result.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LXSTVAYNE, 2021-11-01
@L1MO

Download a picture from a message in a telegram, then upload it to the VKontakte server and send it in the request in the attachments field. In theory, your attachment should look like this: photo66748_265827614. Here is an example for sending a photo: https://github.com/python273/vk_api/blob/master/ex... . And here you can see how to download photos: https://ru.stackoverflow.com/questions/1080264/aio... .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question