create error_msg function (+utils.py)

This commit is contained in:
yuki 2025-10-06 23:56:35 -03:00
parent 8f8eb83b43
commit 45ab8ce67a
2 changed files with 8 additions and 3 deletions

View file

@ -3,6 +3,8 @@ import tomllib
import nerimity import nerimity
import pylast import pylast
import utils
with open("config.toml", "rb") as f: with open("config.toml", "rb") as f:
config = tomllib.load(f) config = tomllib.load(f)
@ -54,13 +56,14 @@ async def fm(ctx: nerimity.Context, params: str = ""):
await ctx.send(f"Now playing for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})") await ctx.send(f"Now playing for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})")
else: else:
await ctx.send(f"Last played for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})") await ctx.send(f"Last played for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})")
except IndexError: except IndexError:
await ctx.send("[#e5323b]Error: User has no recent tracks or they're set to private.") await ctx.send(utils.error_msg("User has no recent tracks or they're set to private."))
except pylast.WSError: except pylast.WSError:
await ctx.send("[#e5323b]Error: User not found.") await ctx.send(utils.error_msg("User not found."))
except Exception as e: except Exception as e:
print(e) print(e)
await ctx.send("[#e5323b]Unknown error.") await ctx.send(utils.error_msg("Unknown error."))
@client.listen("on_ready") @client.listen("on_ready")
async def on_ready(params): async def on_ready(params):

2
utils.py Normal file
View file

@ -0,0 +1,2 @@
def error_msg(message: str):
return f"[#e5323b][Error] [#reset]{message}"