From e49d271c80d46ab29769f070c89103f67fba438d Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Mon, 27 May 2024 17:34:26 +0100 Subject: [PATCH] Perform validation in on_connect --- src/main.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main.py b/src/main.py index 49a1a56..14048c9 100644 --- a/src/main.py +++ b/src/main.py @@ -111,6 +111,21 @@ class Client(commands.Bot): super().__init__(*args, **kwargs) self.web: typing.Optional[asyncio.Task] = None self.uptime_thread = None + + async def on_connect(self): + log.debug("Walking the following application commands: %r", list(self.walk_application_commands())) + for command in self.walk_application_commands(): + log.debug("Checking %r", command) + try: + assert command.input_type is not None, "Input type was None!" + _ = command.to_dict() + except Exception as e: + log.error("Failed to convert %r to dict", command, exc_info=e) + self.remove_application_command(command) + else: + log.debug("Loaded command %r.", command) + log.info("Connected to Discord.") + super().on_connect() async def start(self, token: str, *, reconnect: bool = True) -> None: if CONFIG["jimmy"].get("uptime_kuma_url"): @@ -276,16 +291,4 @@ if __disabled: else: log.info("No commands to disable. Full steam ahead!") -log.debug("Walking the following application commands: %r", list(bot.walk_application_commands())) -for command in bot.walk_application_commands(): - log.debug("Checking %r", command) - try: - assert command.input_type is not None, "Input type was None!" - d = command.to_dict() - except Exception as e: - log.error("Failed to convert %r to dict", command, exc_info=e) - bot.remove_application_command(command) - else: - log.debug("Loaded command %r.", command) - bot.run(CONFIG["jimmy"]["token"])