From 8f55c6083a075691f7a91280a65962be4d71445e Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Sat, 25 May 2024 17:24:04 -0400 Subject: [PATCH] fix(speedtest): improve an error message --- speedtest/speedtest.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/speedtest/speedtest.py b/speedtest/speedtest.py index ea1daa4..1d10019 100644 --- a/speedtest/speedtest.py +++ b/speedtest/speedtest.py @@ -56,16 +56,19 @@ class Speedtest(commands.Cog): msg = await ctx.maybe_send_embed("Running speedtest...") async with ctx.typing(): r = await self.run_speedtest() - if isinstance(r, str): - await msg.edit(content=f"An error occurred: {r}") - return if await ctx.embed_requested(): + if isinstance(r, str): + await msg.edit(embed=discord.Embed(description=f"An error occurred! {r}", color=await discord.Colour.red())) + return embed = discord.Embed(title="Speedtest Results", link=r["result"]["url"], color=await ctx.embed_color()) embed.add_field(name="Bandwidth", value=f"{r['download']['bandwidth'] / 1_000_000:.2f} Mbps down, {r['upload']['bandwidth'] / 1_000_000:.2f} Mbps up") embed.add_field(name="Ping", value=f"Base: {round(r['ping']['latency'])} ms \nDownload: {round(r['download']['latency']['igm'])} ms \nUpload: {round(r['upload']['latency']['igm'])} ms") embed.set_image(url=r["result"]["image"] + ".png") await msg.edit(embed=embed) else: + if isinstance(r, str): + await msg.edit(content=f"An error occurred! {r}") + return await msg.edit(content=f"**Speedtest Results**\n" f"**Bandwidth**: {r['download']['bandwidth'] / 1_000_000:.2f} Mbps down, {r['upload']['bandwidth'] / 1_000_000:.2f} Mbps up\n" f"**Ping**: Base: {round(r['ping']['latency'])} ms, Download: {round(r['download']['latency']['igm'])} ms, Upload: {round(r['upload']['latency']['igm'])} ms\n"