Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

notify user if something went wrong when running browser-use

Malik Talhaa6b80361f548
diff --git a/examples/discord_api.py b/examples/discord_api.py
index 33ad4720f..57c247ab6 100644
--- a/examples/discord_api.py
+++ b/examples/discord_api.py
@@ -86,9 +86,14 @@ class DiscordBot(commands.Bot):
llm=self.llm,
browser=browser
)
-
result = await agent.run()
- return result.history[-1].result[0].extracted_content
+
+ if result.is_done():
+ agent_message = result.history[-1].result[0].extracted_content
+ else:
+ agent_message = "Oops! Something went wrong while running Browser-Use."
+
+ return agent_message
except Exception as e:
raise Exception(f"Browser-use task failed: {str(e)}")