Обращению к масиву рандомных картинок
Есть масив из картинок randoming. Как заставить бота обращаться к нему и брать оттуда картинку рандомно?
import amino
import random
import datetime
from gtts import gTTS
import requests
import os
import time
import threading
from threading import Thread
import subprocess
from io import BytesIO
from getpass import getpass
def on_message(data):
content = data.message.content
chatId = data.message.chatId
randomimg = ["amino.jpeg", "amino2.jpeg"] # рандом картинка
if content.lower().startswith("nsercet"):
with open("randomimg", "rb") as file:
sub_client.send_message(chatId=chatId, file=file, fileType="image")
Ответы (1 шт):
Автор решения: CrazyElf
→ Ссылка
Используйте random.choice:
with open(random.choice(randomimg), "rb") as file: