Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ class MyClient(discord.Client):
|
|
42 |
# λ΄μ΄ μμλ λ μλ΄ λ©μμ§λ₯Ό μ μ‘
|
43 |
channel = self.get_channel(SPECIFIC_CHANNEL_ID)
|
44 |
if channel:
|
45 |
-
await channel.send("μ°Ύκ³ μΆμ
|
46 |
|
47 |
async def on_message(self, message):
|
48 |
if message.author == self.user:
|
@@ -101,7 +101,7 @@ async def search_videos(keywords):
|
|
101 |
}
|
102 |
params = {
|
103 |
"query": keywords,
|
104 |
-
"per_page":
|
105 |
}
|
106 |
response = requests.get(PEXELS_API_VIDEO_URL, headers=headers, params=params)
|
107 |
if response.status_code == 200:
|
@@ -114,11 +114,10 @@ async def search_videos(keywords):
|
|
114 |
return None
|
115 |
|
116 |
async def create_or_use_thread_and_send_videos(message, keywords, video_urls):
|
117 |
-
# λ©μμ§μ μ΄λ―Έ
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
else:
|
122 |
# μ μ°λ λ μμ±
|
123 |
thread = await message.channel.create_thread(name=f"{message.author.name}μ κ²μ κ²°κ³Ό", message=message)
|
124 |
|
@@ -127,6 +126,15 @@ async def create_or_use_thread_and_send_videos(message, keywords, video_urls):
|
|
127 |
for url in video_urls:
|
128 |
await thread.send(url)
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
if __name__ == "__main__":
|
131 |
discord_client = MyClient(intents=intents)
|
132 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
|
|
42 |
# λ΄μ΄ μμλ λ μλ΄ λ©μμ§λ₯Ό μ μ‘
|
43 |
channel = self.get_channel(SPECIFIC_CHANNEL_ID)
|
44 |
if channel:
|
45 |
+
await channel.send("μ°Ύκ³ μΆμ λμμμ λν μ€λͺ
μ ν λ¬Έμ₯ λ¨μλ‘ μ
λ ₯νμΈμ. μ) λλ°μμ λ°μ΄ λ
Έλ κ°μμ§")
|
46 |
|
47 |
async def on_message(self, message):
|
48 |
if message.author == self.user:
|
|
|
101 |
}
|
102 |
params = {
|
103 |
"query": keywords,
|
104 |
+
"per_page": 20 # μ΅λ 20κ° λμμμ κ°μ Έμ΅λλ€
|
105 |
}
|
106 |
response = requests.get(PEXELS_API_VIDEO_URL, headers=headers, params=params)
|
107 |
if response.status_code == 200:
|
|
|
114 |
return None
|
115 |
|
116 |
async def create_or_use_thread_and_send_videos(message, keywords, video_urls):
|
117 |
+
# λ©μμ§μ λν΄ μ΄λ―Έ μμ±λ μ°λ λλ₯Ό μ°Ύμ
|
118 |
+
thread = await find_existing_thread(message)
|
119 |
+
|
120 |
+
if not thread:
|
|
|
121 |
# μ μ°λ λ μμ±
|
122 |
thread = await message.channel.create_thread(name=f"{message.author.name}μ κ²μ κ²°κ³Ό", message=message)
|
123 |
|
|
|
126 |
for url in video_urls:
|
127 |
await thread.send(url)
|
128 |
|
129 |
+
async def find_existing_thread(message):
|
130 |
+
# μ±λμ λͺ¨λ μ°λ λ κ°μ Έμ€κΈ°
|
131 |
+
threads = await message.channel.threads()
|
132 |
+
# μ£Όμ΄μ§ λ©μμ§μ μ°κ΄λ μ°λ λλ₯Ό μ°ΎκΈ°
|
133 |
+
for thread in threads:
|
134 |
+
if thread.id == message.id:
|
135 |
+
return thread
|
136 |
+
return None
|
137 |
+
|
138 |
if __name__ == "__main__":
|
139 |
discord_client = MyClient(intents=intents)
|
140 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|