Fix slash_command and normal_command bools

This commit is contained in:
Gnome 2021-09-02 12:33:48 +01:00
parent caa5f39c0f
commit 355097589a
2 changed files with 11 additions and 19 deletions

View File

@ -181,6 +181,7 @@ class BotBase(GroupMixin):
self.owner_id = options.get('owner_id')
self.owner_ids = options.get('owner_ids', set())
self.strip_after_prefix = options.get('strip_after_prefix', False)
self.slash_command_guilds: Optional[Iterable[int]] = options.get('slash_command_guilds', None)
if self.owner_id and self.owner_ids:
raise TypeError('Both owner_id and owner_ids are set.')
@ -190,8 +191,6 @@ class BotBase(GroupMixin):
if not (message_commands or slash_commands):
raise TypeError("Both message_commands and slash_commands are disabled.")
elif slash_commands:
self.slash_command_guilds: Optional[Iterable[int]] = options.get('slash_command_guilds', None)
if help_command is _default:
self.help_command = DefaultHelpCommand()
@ -211,7 +210,7 @@ class BotBase(GroupMixin):
async def _create_application_commands(self, application_id: int, http: HTTPClient):
commands: defaultdict[Optional[int], List[EditApplicationCommand]] = defaultdict(list)
for command in self.commands:
if command.hidden:
if command.hidden or (command.slash_command is None and not self.slash_commands):
continue
payload = command.to_application_command()
@ -1196,12 +1195,10 @@ class BotBase(GroupMixin):
async def on_message(self, message):
if self.message_commands:
await self.process_commands(message)
await self.process_commands(message)
async def on_interaction(self, interaction: discord.Interaction):
if self.slash_commands and interaction.type == discord.InteractionType.application_command:
await self.process_slash_commands(interaction)
await self.process_slash_commands(interaction)
class Bot(BotBase, discord.Client):
@ -1297,9 +1294,6 @@ class Bot(BotBase, discord.Client):
"""
async def setup(self):
if not self.slash_commands:
return
application = self.application_id or (await self.application_info()).id
await self._create_application_commands(application, self.http)
@ -1308,8 +1302,5 @@ class AutoShardedBot(BotBase, discord.AutoShardedClient):
:class:`discord.AutoShardedClient` instead.
"""
async def setup(self):
if not self.slash_commands:
return
application = self.application_id or (await self.application_info()).id
await self._create_application_commands(application, self.http)

View File

@ -1142,13 +1142,14 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
:class:`bool`
A boolean indicating if the command can be invoked.
"""
if not self.enabled or (
ctx.interaction is not None
and self.slash_command is False
) or (
ctx.interaction is None
and self.message_command is False
ctx.interaction is None and (
self.message_command is False
or (self.message_command is None and not ctx.bot.message_commands)
) or (
self.slash_command is False
or (self.slash_command is None and not ctx.bot.slash_commands)
)
):
raise DisabledCommand(f'{self.name} command is disabled')