From c37a58d687a68f3f97bb3c14491ffef1f1915f1c Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 1 Feb 2024 19:37:47 -0500 Subject: [PATCH] fix(bible): fixed error handling for bible commands --- bible/bible.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/bible/bible.py b/bible/bible.py index 0612646..f86e4ca 100644 --- a/bible/bible.py +++ b/bible/bible.py @@ -34,23 +34,6 @@ class Bible(commands.Cog): self.config.register_global(bible="de4e12af7f28f599-01") self.config.register_user(bible=None) - async def on_command_error(self, ctx: commands.Context, err): - if isinstance(err, bible.errors.Unauthorized): - await ctx.send( - error( - """The API key for API.bible is missing or invalid. Please report this to the bot owner. - If you are the bot owner, please check the documentation [here](https://seacogs.coastalcommits.com/bible/#setup).""" - ) - ) - if isinstance(err, bible.errors.BibleAccessError): - await ctx.send( - error( - "The provided API key cannot retrieve sections from the configured Bible. Please report this to the bot owner." - ) - ) - if isinstance(err, bible.errors.NotFound): - await ctx.send(error("The requested passage was not found.")) - async def translate_book_name(self, bible_id: str, book_name: str) -> str: """Translate a book name to a book ID.""" book_name_list = book_name.split() @@ -216,3 +199,25 @@ class Bible(commands.Cog): ) embed.set_footer(text=f"{ctx.prefix}bible random - Powered by API.bible") await ctx.send(embed=embed) + + @bible_passage.error + @bible_random.error + async def error_handler(self, ctx: commands.Context, err): + if isinstance(err, bible.errors.Unauthorized): + await ctx.send( + error( + """The API key for API.bible is missing or invalid. Please report this to the bot owner. + If you are the bot owner, please check the documentation [here](https://seacogs.coastalcommits.com/bible/#setup).""" + ) + ) + return + elif isinstance(err, bible.errors.BibleAccessError): + await ctx.send( + error( + "The provided API key cannot retrieve sections from the configured Bible. Please report this to the bot owner." + ) + ) + return + elif isinstance(err, bible.errors.NotFound): + await ctx.send(error("The requested passage was not found.")) + return