diff --git a/userslash/__init__.py b/userslash/__init__.py index b1f1d74..fda9f69 100644 --- a/userslash/__init__.py +++ b/userslash/__init__.py @@ -135,7 +135,8 @@ class UserSlash(commands.Cog): self, before: discord.User, after: discord.User ) -> None: """Update the slash-command name when the bot's username changes.""" - assert self.bot.user + if not self.bot.user: + raise AssertionError if after.id != self.bot.user.id or before.name == after.name: return diff --git a/userslash/context.py b/userslash/context.py index abbf13d..39ba7f7 100644 --- a/userslash/context.py +++ b/userslash/context.py @@ -63,7 +63,8 @@ class InterContext(commands.Context): try: self = contexts.get() if recreate_message: - assert self.prefix is not None + if self.prefix is None: + raise AssertionError self.message._recreate_from_interaction(interaction, prefix) view = self.view = StringView(self.message.content) view.skip_string(self.prefix) @@ -155,7 +156,8 @@ class InterContext(commands.Context): command = self.bot.get_command(command) or command signature: str if signature := getattr(command, "signature", ""): - assert not isinstance(command, str) + if isinstance(command, str): + raise AssertionError() command = copy(command) command.usage = f"arguments:{signature}" return await super().send_help(command) diff --git a/userslash/message.py b/userslash/message.py index 32a8591..46e7a97 100644 --- a/userslash/message.py +++ b/userslash/message.py @@ -49,7 +49,8 @@ class InterMessage(discord.Message): def _from_interaction( cls, interaction: discord.Interaction, prefix: str ) -> "InterMessage": - assert interaction.data + if not interaction.data: + raise AssertionError assert interaction.client.user self = cls.__new__(cls) @@ -126,7 +127,8 @@ class InterMessage(discord.Message): @staticmethod def _make_dm_channel(interaction: discord.Interaction) -> discord.DMChannel: """Fabricate a minimal DMChannel when the real one is unavailable.""" - assert interaction.client.user + if not interaction.client.user: + raise AssertionError user = interaction.user user_json = ( user._to_minimal_user_json() @@ -156,7 +158,8 @@ class InterMessage(discord.Message): def _recreate_from_interaction( self, interaction: discord.Interaction, prefix: str ) -> None: - assert interaction.data and interaction.client.user + if not (interaction.data and interaction.client.user): + raise AssertionError self.content = f"{prefix}{interaction.namespace.command}" if interaction.namespace.arguments: diff --git a/userslash/slash_bridge.py b/userslash/slash_bridge.py index 71cde72..33015d7 100644 --- a/userslash/slash_bridge.py +++ b/userslash/slash_bridge.py @@ -357,7 +357,8 @@ async def _autocomplete( @user_slash_command.error async def _error(interaction: discord.Interaction, error: Exception): - assert isinstance(interaction.client, Red) + if not isinstance(interaction.client, Red): + raise AssertionError # Log the original error for debugging LOG.error(f"Slash command error for user {interaction.user.id}: {error}", exc_info=error)