diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 81ca0b7d..8973e8ec 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -99,11 +99,13 @@ class _FakeSlashMessage(discord.PartialMessage): tts = False @classmethod - def from_interaction(cls, interaction: discord.Interaction) -> discord.Message: - self: discord.Message = cls(channel=interaction.channel, id=interaction.id) # type: ignore - + def from_interaction( + cls, interaction: discord.Interaction, channel: Union[discord.TextChannel, discord.DMChannel, discord.Thread] + ): + self = cls(channel=channel, id=interaction.id) assert interaction.user is not None self.author = interaction.user + return self @@ -233,7 +235,7 @@ class BotBase(GroupMixin): raise TypeError(f"owner_ids must be a collection not {self.owner_ids.__class__!r}") if not (message_commands or slash_commands): - raise TypeError("Both message_commands and slash_commands are disabled.") + raise ValueError("Both message_commands and slash_commands are disabled.") if help_command is _default: self.help_command = DefaultHelpCommand() @@ -1259,11 +1261,8 @@ class BotBase(GroupMixin): else: return # cannot do anything without stable channel - interaction.channel = channel # type: ignore - del channel - # Fetch a valid prefix, so process_commands can function - message = _FakeSlashMessage.from_interaction(interaction) + message: discord.Message = _FakeSlashMessage.from_interaction(interaction, channel) # type: ignore prefix = await self.get_prefix(message) if isinstance(prefix, list): prefix = prefix[0] diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index ed1b8bfe..fa1e4212 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -429,7 +429,9 @@ class Command(_BaseCommand, Generic[CogT, P, T]): parent = kwargs.get("parent") self.parent: Optional[GroupMixin] = parent if isinstance(parent, _BaseCommand) else None # type: ignore if self.slash_command_guilds is not None and self.parent is not None: - raise TypeError("Cannot set specific guilds for a subcommand. They are inherited from the top level group.") + raise ValueError( + "Cannot set specific guilds for a subcommand. They are inherited from the top level group." + ) self._before_invoke: Optional[Hook] = None try: