wop commited on
Commit
704f32c
·
verified ·
1 Parent(s): 598903b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -221,20 +221,21 @@ async def on_member_join(member):
221
  @bot.command()
222
  async def search(ctx, *, query: str):
223
  """Search for a bible verse."""
224
- bible_api_url = f"https://labs.bible.org/api/?passage={query}&type=json"
225
- response = requests.get(bible_api_url)
226
-
227
- if response.status_code == 200:
 
228
  verses = response.json()
229
  if verses:
230
  # If verses are found, concatenate them into a single message
231
- passage = "\n".join(f"**{verse['bookname']} {verse['chapter']}:{verse['verse']}** \n{verse['text']}" for verse in verses)
232
  passage = truncate_response(passage)
233
  embed = discord.Embed(title=f"Search Results for '{query}'", description=passage, color=discord.Color.blue())
234
  else:
235
  embed = discord.Embed(title="Search Results", description="No results found.", color=discord.Color.red())
236
- else:
237
- embed = discord.Embed(title="Search Results", description="Unable to fetch search results.", color=discord.Color.red())
238
 
239
  embed.set_footer(text="Created by Cosmos")
240
  await ctx.reply(embed=embed)
 
221
  @bot.command()
222
  async def search(ctx, *, query: str):
223
  """Search for a bible verse."""
224
+ bible_api_url = f"http://labs.bible.org/api/?passage={query}&formatting=plain&type=json"
225
+ try:
226
+ response = requests.get(bible_api_url)
227
+ response.raise_for_status()
228
+
229
  verses = response.json()
230
  if verses:
231
  # If verses are found, concatenate them into a single message
232
+ passage = "\n".join(verses)
233
  passage = truncate_response(passage)
234
  embed = discord.Embed(title=f"Search Results for '{query}'", description=passage, color=discord.Color.blue())
235
  else:
236
  embed = discord.Embed(title="Search Results", description="No results found.", color=discord.Color.red())
237
+ except requests.RequestException as e:
238
+ embed = discord.Embed(title="Search Results", description=f"Error: {e}", color=discord.Color.red())
239
 
240
  embed.set_footer(text="Created by Cosmos")
241
  await ctx.reply(embed=embed)