How to get the url of a photo via vk real?

22 views Asked by At

Code:

import vkreal
import discord
from discord.ext import commands
import asyncio

client = commands.Bot(command_prefix='!', intents=discord.Intents.all())

chat_id1 = 2000000008

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
token = "TOKEN"
session = vkreal.VkApi(token, sess = None, v = "5.125")
longpoll = vkreal.VkLongPoll(session, loop = loop)

async def disbot():
    async for event in longpoll.listen():
        if event["type"] == 4 and event["peer_id"] == chat_id1:
            user_id = event["data"]
            message = event["text"]
            attachments = event["attachments"]
            user_info = await session.method("users.get", {"user_ids": user_id.get('from')})
            user_name = user_info[0]['first_name'] + ' ' + user_info[0]['last_name']
            await client.wait_until_ready()
            channel = client.get_channel(channel_id)
            if 'attach1_type' in attachments:
                if attachments.get('attach1_type') == "photo":
                    print(attachments)
                    await channel.send(f"{user_name} » {message} [Photo]")
                else:
                    await channel.send(f"{user_name} » {message}")
            else:
                await channel.send(f"{user_name} » {message}")
@client.event
async def on_ready():
    print('Bot connected!')

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    await client.process_commands(message)

async def main():
    async with client:
        client.loop.create_task(disbot())
        await client.start('BotToken')

asyncio.run(main())

I need to get the url of a photo using vk real. But in event[“attachments”] there is only {'attach1_type': 'photo', 'attach1': '527908974_457239108'}. I didn't find the required data for the url. Is there any way or method vk to get the url? I will be very grateful for your help.

0

There are 0 answers