Fix slash_command and normal_command bools
This commit is contained in:
parent
caa5f39c0f
commit
355097589a
@ -181,6 +181,7 @@ class BotBase(GroupMixin):
|
|||||||
self.owner_id = options.get('owner_id')
|
self.owner_id = options.get('owner_id')
|
||||||
self.owner_ids = options.get('owner_ids', set())
|
self.owner_ids = options.get('owner_ids', set())
|
||||||
self.strip_after_prefix = options.get('strip_after_prefix', False)
|
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:
|
if self.owner_id and self.owner_ids:
|
||||||
raise TypeError('Both owner_id and owner_ids are set.')
|
raise TypeError('Both owner_id and owner_ids are set.')
|
||||||
@ -190,8 +191,6 @@ class BotBase(GroupMixin):
|
|||||||
|
|
||||||
if not (message_commands or slash_commands):
|
if not (message_commands or slash_commands):
|
||||||
raise TypeError("Both message_commands and slash_commands are disabled.")
|
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:
|
if help_command is _default:
|
||||||
self.help_command = DefaultHelpCommand()
|
self.help_command = DefaultHelpCommand()
|
||||||
@ -211,7 +210,7 @@ class BotBase(GroupMixin):
|
|||||||
async def _create_application_commands(self, application_id: int, http: HTTPClient):
|
async def _create_application_commands(self, application_id: int, http: HTTPClient):
|
||||||
commands: defaultdict[Optional[int], List[EditApplicationCommand]] = defaultdict(list)
|
commands: defaultdict[Optional[int], List[EditApplicationCommand]] = defaultdict(list)
|
||||||
for command in self.commands:
|
for command in self.commands:
|
||||||
if command.hidden:
|
if command.hidden or (command.slash_command is None and not self.slash_commands):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
payload = command.to_application_command()
|
payload = command.to_application_command()
|
||||||
@ -1196,12 +1195,10 @@ class BotBase(GroupMixin):
|
|||||||
|
|
||||||
|
|
||||||
async def on_message(self, message):
|
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):
|
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):
|
class Bot(BotBase, discord.Client):
|
||||||
@ -1297,9 +1294,6 @@ class Bot(BotBase, discord.Client):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
async def setup(self):
|
async def setup(self):
|
||||||
if not self.slash_commands:
|
|
||||||
return
|
|
||||||
|
|
||||||
application = self.application_id or (await self.application_info()).id
|
application = self.application_id or (await self.application_info()).id
|
||||||
await self._create_application_commands(application, self.http)
|
await self._create_application_commands(application, self.http)
|
||||||
|
|
||||||
@ -1308,8 +1302,5 @@ class AutoShardedBot(BotBase, discord.AutoShardedClient):
|
|||||||
:class:`discord.AutoShardedClient` instead.
|
:class:`discord.AutoShardedClient` instead.
|
||||||
"""
|
"""
|
||||||
async def setup(self):
|
async def setup(self):
|
||||||
if not self.slash_commands:
|
|
||||||
return
|
|
||||||
|
|
||||||
application = self.application_id or (await self.application_info()).id
|
application = self.application_id or (await self.application_info()).id
|
||||||
await self._create_application_commands(application, self.http)
|
await self._create_application_commands(application, self.http)
|
||||||
|
@ -1142,13 +1142,14 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
|||||||
:class:`bool`
|
:class:`bool`
|
||||||
A boolean indicating if the command can be invoked.
|
A boolean indicating if the command can be invoked.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.enabled or (
|
if not self.enabled or (
|
||||||
ctx.interaction is not None
|
ctx.interaction is None and (
|
||||||
and self.slash_command is False
|
self.message_command is False
|
||||||
) or (
|
or (self.message_command is None and not ctx.bot.message_commands)
|
||||||
ctx.interaction is None
|
) or (
|
||||||
and self.message_command is False
|
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')
|
raise DisabledCommand(f'{self.name} command is disabled')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user