From 9f42046565b9a95e9d3f52108bc894ef1ed400d9 Mon Sep 17 00:00:00 2001 From: xsnowstorm <118460071+xsnowstorm@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:42:08 +0000 Subject: [PATCH 1/2] Fixed help command --- bot/commands/utility/help.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bot/commands/utility/help.py b/bot/commands/utility/help.py index 09b84f3a..60c3e108 100644 --- a/bot/commands/utility/help.py +++ b/bot/commands/utility/help.py @@ -1,6 +1,6 @@ import asyncio -from bot.base import Command +from bot.base import Command, Logger from bot.config import Config, Embed @@ -155,14 +155,14 @@ async def execute(self, arguments, message) -> None: except KeyError: try: cmdobj = [ - [c for c in i.commands if c.name == command] - for i in bot.manager.categories + [c for c in i.commands if c.name == args[0]] + for i in self.manager.categories if i.prefix is None ] cmdobj = [i for i in cmdobj if len(i) != 0][0][0] - return self.command_help(message, cmdobj) + return await self.command_help(message, cmdobj) except IndexError: - return await logger.send_error( - f"Command '{command}' not found", message + return await Logger.send_error( + f"Command '{args[0]}' not found", message ) return await self.command_help(message, cmdobj) From 6cfdd585d925d1242449be696f60ecfa7520dce4 Mon Sep 17 00:00:00 2001 From: xsnowstorm <118460071+xsnowstorm@users.noreply.github.com> Date: Sat, 4 Nov 2023 13:01:43 +0000 Subject: [PATCH 2/2] use raise instead of logger.send_error --- bot/__main__.py | 3 ++- bot/commands/utility/help.py | 19 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/bot/__main__.py b/bot/__main__.py index da66d65c..b3abf5b7 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -361,7 +361,8 @@ async def on_message(message: discord.Message): or not bot.is_ready() or message.channel.id == config.general_channel ): - await bot.event_manager.event_map()["on_message"].execute(message) + if not "on_message.py" in Config.testing["ignored_files"]: + await bot.event_manager.event_map()["on_message"].execute(message) return command, arguments = parse_user_input(message.content[len(config.prefix) :]) diff --git a/bot/commands/utility/help.py b/bot/commands/utility/help.py index 60c3e108..e2e5002e 100644 --- a/bot/commands/utility/help.py +++ b/bot/commands/utility/help.py @@ -1,9 +1,8 @@ import asyncio -from bot.base import Command, Logger +from bot.base import Command from bot.config import Config, Embed - class cmd(Command): """Help command.""" @@ -45,7 +44,7 @@ async def category_help(self, message, name="") -> None: title=f"{name} - Page {page+1} / {len(categories)+1}", description=f"List of all commands and their description\nRun `{Config.prefix}{self.usage}` to get information about a specific command (still wip).\n\n", ) - embed.set_author(name=f"Help menu") + embed.set_author(name="Help menu") for idx, command in zip(range(len(commands)), commands): print(command, idx) @@ -68,7 +67,7 @@ def check(reaction, user): ] try: - reaction, user = await self.bot.wait_for( + reaction, _ = await self.bot.wait_for( "reaction_add", timeout=120.0, check=check ) except asyncio.TimeoutError: @@ -107,7 +106,7 @@ def check(reaction, user): return user == message.author and str(reaction.emoji) in ["↩️"] try: - reaction, user = await self.bot.wait_for( + reaction, _ = await self.bot.wait_for( "reaction_add", timeout=120.0, check=check ) except asyncio.TimeoutError: @@ -145,8 +144,8 @@ async def execute(self, arguments, message) -> None: i.prefix: i for i in self.manager.categories if i.prefix is not None }[args[0]].commands_map()[args[1]] return await self.command_help(message, cmdobj) - except KeyError: - raise KeyError(f"Command {args[0]} {args[1]} not found") + except KeyError as exc: + raise KeyError(f"Command {args[0]} {args[1]} not found") from exc except IndexError: return await self.category_help(message, args[0]) else: @@ -161,8 +160,6 @@ async def execute(self, arguments, message) -> None: ] cmdobj = [i for i in cmdobj if len(i) != 0][0][0] return await self.command_help(message, cmdobj) - except IndexError: - return await Logger.send_error( - f"Command '{args[0]}' not found", message - ) + except IndexError as exc: + raise IndexError(f"Command '{args[0]}' not found") from exc return await self.command_help(message, cmdobj)