fix(speedtest): improve an error message
This commit is contained in:
parent
4795df7dcc
commit
8f55c6083a
1 changed files with 6 additions and 3 deletions
|
@ -56,16 +56,19 @@ class Speedtest(commands.Cog):
|
||||||
msg = await ctx.maybe_send_embed("Running speedtest...")
|
msg = await ctx.maybe_send_embed("Running speedtest...")
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
r = await self.run_speedtest()
|
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 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 = 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="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.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")
|
embed.set_image(url=r["result"]["image"] + ".png")
|
||||||
await msg.edit(embed=embed)
|
await msg.edit(embed=embed)
|
||||||
else:
|
else:
|
||||||
|
if isinstance(r, str):
|
||||||
|
await msg.edit(content=f"An error occurred! {r}")
|
||||||
|
return
|
||||||
await msg.edit(content=f"**Speedtest Results**\n"
|
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"**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"
|
f"**Ping**: Base: {round(r['ping']['latency'])} ms, Download: {round(r['download']['latency']['igm'])} ms, Upload: {round(r['upload']['latency']['igm'])} ms\n"
|
||||||
|
|
Loading…
Reference in a new issue