Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -57,10 +57,10 @@ class MyClient(discord.Client):
|
|
57 |
keywords = await extract_keywords(message)
|
58 |
if keywords:
|
59 |
# Pexels APIλ‘ κ³ ν΄μλ μ΄λ―Έμ§ κ²μ
|
60 |
-
|
61 |
-
if
|
62 |
# λμ€μ½λ μ±λμ μ΄λ―Έμ§ μ μ‘
|
63 |
-
await send_images(message.channel, keywords,
|
64 |
else:
|
65 |
await message.channel.send(f"**{keywords}**μ λν κ³ ν΄μλ μ΄λ―Έμ§λ₯Ό μ°Ύμ μ μμ΅λλ€.")
|
66 |
else:
|
@@ -116,11 +116,21 @@ async def search_images(keywords):
|
|
116 |
async def send_images(channel, keywords, image_infos):
|
117 |
message_content = f"**{keywords}**μ λν κ³ ν΄μλ μ΄λ―Έμ§ {len(image_infos)}μ₯μ μ°Ύμμ΅λλ€:"
|
118 |
await channel.send(message_content)
|
|
|
|
|
119 |
for info in image_infos:
|
120 |
-
embed = discord.Embed(title=info["title"], url=info["url"])
|
121 |
-
embed.set_image(url=info["url"])
|
122 |
embed.set_thumbnail(url=info["thumbnail"])
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
if __name__ == "__main__":
|
126 |
discord_client = MyClient(intents=intents)
|
|
|
57 |
keywords = await extract_keywords(message)
|
58 |
if keywords:
|
59 |
# Pexels APIλ‘ κ³ ν΄μλ μ΄λ―Έμ§ κ²μ
|
60 |
+
image_infos = await search_images(keywords)
|
61 |
+
if image_infos:
|
62 |
# λμ€μ½λ μ±λμ μ΄λ―Έμ§ μ μ‘
|
63 |
+
await send_images(message.channel, keywords, image_infos)
|
64 |
else:
|
65 |
await message.channel.send(f"**{keywords}**μ λν κ³ ν΄μλ μ΄λ―Έμ§λ₯Ό μ°Ύμ μ μμ΅λλ€.")
|
66 |
else:
|
|
|
116 |
async def send_images(channel, keywords, image_infos):
|
117 |
message_content = f"**{keywords}**μ λν κ³ ν΄μλ μ΄λ―Έμ§ {len(image_infos)}μ₯μ μ°Ύμμ΅λλ€:"
|
118 |
await channel.send(message_content)
|
119 |
+
embeds = []
|
120 |
+
|
121 |
for info in image_infos:
|
122 |
+
embed = discord.Embed(title=info["title"], url=info["url"], description=f"[κ³ ν΄μλ μ΄λ―Έμ§ 보기]({info['url']})")
|
|
|
123 |
embed.set_thumbnail(url=info["thumbnail"])
|
124 |
+
embeds.append(embed)
|
125 |
+
|
126 |
+
# λμ€μ½λ μλ² λ λ©μμ§λ ν λ²μ μ΅λ 10κ°κΉμ§ 보λ΄λ―λ‘ ν λ²μ 보λ΄κΈ°
|
127 |
+
if len(embeds) == 10:
|
128 |
+
await channel.send(embeds=embeds)
|
129 |
+
embeds = []
|
130 |
+
|
131 |
+
# λ¨μ μλ² λ μ μ‘
|
132 |
+
if embeds:
|
133 |
+
await channel.send(embeds=embeds)
|
134 |
|
135 |
if __name__ == "__main__":
|
136 |
discord_client = MyClient(intents=intents)
|