Skip to content

Commit

Permalink
added error collection
Browse files Browse the repository at this point in the history
  • Loading branch information
elouangrimm authored Oct 29, 2024
1 parent bc95e87 commit 6709f97
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def send_daily_tip():

# ☲☲☲☲ COMMANDS ☲☲☲☲

# Response to a Ping
# Response to a Ping with AI
@bot.event
async def on_message(message):
if bot.user.mentioned_in(message):
Expand All @@ -98,9 +98,30 @@ async def on_message(message):
response = requests.post(api_url, headers=headers, json=data)

if response.status_code == 200:
reply_text = response.json().get("generated_text", "Hmm... not sure what to say! 😅")
else:
reply_text = "Sorry, I'm having trouble thinking right now! 🧠💤"
json_data = response.json()
print(json_data)
if "generated_text" in json_data:
reply_text = json_data["generated_text"]
print("AI: Message Generated, Code 200")
else:
reply_text = "Hmm... couldn't quite generate a response! 😅"
print("AI: Unknown Error")
elif response.status_code == 401:
reply_text = "Authentication failed! Check your API token. 🔑🚫"
print("AI: API Error, Code 401")
elif response.status_code == 429:
reply_text = "Whoa, too many requests! Slow down a bit 🐢💨"
print("AI: Too Many Requests, Code 429")
elif response.status_code == 500:
reply_text = "The server seems to be having issues! Try again later. 🛠️"
print("AI: Server Issues, Code 500")
else:
reply_text = f"Unexpected error: {response.status_code}. 😕"
print(f"AI: Unexpected Error, Code {response.status_code}")

except requests.exceptions.RequestException as e:
reply_text = f"Network error: {str(e)} 🚨"
print("AI: Network Error")

await message.reply(reply_text)
await bot.process_commands(message)
Expand Down

0 comments on commit 6709f97

Please sign in to comment.