Answer the question
In order to leave comments, you need to log in
How to attach a file from a folder to a VK message?
I want the bot to select a random file (photo) from the "citati" folder and attach it to the message. But, instead, when sending a command - it writes the following:
Command:
!m random quote
Random Quote:
<_io.TextIOWrapper name='citati/cb5cee35d576980a28e7128d1be6c616.jpg' mode='r' encoding='cp1251'>
async def cit(delay, peer_id, command):
await asyncio.sleep(delay)
if "!м рандом цитата" in command:
try:
P_time = datetime.now().timestamp()
requests = get(f'https://api.vk.com/method/messages.getConversations?count=20?filter=all?v=5.89&access_token=dba88f4f906b28feee2728472f4')
DIR = 'citati/'
F = open(os.path.join(DIR, random.choice(os.listdir(DIR))))
msg_1 = f"""
Рандомная Цитата: \n {F}
""".replace(' ', '')
messages.write_msg(peer_id, msg_1)
#time.sleep(3)
except Exception as Errpeng:
print(f"Ошибка цитаты: {Errpeng}")
Answer the question
In order to leave comments, you need to log in
You are too beginner pythonist to solve such problems intuitively. You need to learn.
F = open(os.path.join(DIR, random.choice(os.listdir(DIR))))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question