diff --git a/main.py b/main.py index 3a15fec..56da999 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ import tomllib import nerimity import pylast +import utils + with open("config.toml", "rb") as 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})") else: await ctx.send(f"Last played for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})") + 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: - await ctx.send("[#e5323b]Error: User not found.") + await ctx.send(utils.error_msg("User not found.")) except Exception as e: print(e) - await ctx.send("[#e5323b]Unknown error.") + await ctx.send(utils.error_msg("Unknown error.")) @client.listen("on_ready") async def on_ready(params): diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..b8ccc6e --- /dev/null +++ b/utils.py @@ -0,0 +1,2 @@ +def error_msg(message: str): + return f"[#e5323b][Error] [#reset]{message}"