Skip to content

Commit

Permalink
docs: add some missing documentation for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Jul 27, 2022
1 parent 4fcde61 commit e39bffc
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 111 deletions.
19 changes: 19 additions & 0 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ class ApplicationCommand(ABC):
Whether this command can only be used in NSFW channels.
Defaults to ``False``.
.. versionadded:: 2.6
id: Optional[:class:`int]
The ID of the command, if there is a representation on Discord.
.. versionadded:: 2.6
"""

Expand Down Expand Up @@ -627,6 +631,11 @@ class UserCommand(ApplicationCommand):
Whether this command can only be used in NSFW channels.
Defaults to ``False``.
.. versionadded:: 2.6
id: Optional[:class:`int]
The ID of the command, if there is a representation on Discord.
.. versionadded:: 2.6
"""

Expand Down Expand Up @@ -729,6 +738,11 @@ class MessageCommand(ApplicationCommand):
Whether this command can only be used in NSFW channels.
Defaults to ``False``.
.. versionadded:: 2.6
id: Optional[:class:`int]
The ID of the command, if there is a representation on Discord.
.. versionadded:: 2.6
"""

Expand Down Expand Up @@ -842,6 +856,11 @@ class SlashCommand(ApplicationCommand):
options: List[:class:`Option`]
The list of options the slash command has.
id: Optional[:class:`int]
The ID of the command, if there is a representation on Discord.
.. versionadded:: 2.6
"""

__repr_info__ = (
Expand Down
11 changes: 7 additions & 4 deletions disnake/ext/commands/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ def _update_copy(self: AppCommandT, kwargs: Dict[str, Any]) -> AppCommandT:

@property
def id(self) -> Optional[int]:
return self.body.id
"""Optional[:class:`int`]: The ID of this command, if it is synced with Discord.
@id.setter
def id(self, id: int):
self.body.id = id
.. versionadded:: 2.6
"""
return self.body.id

@property
def dm_permission(self) -> bool:
Expand All @@ -244,6 +244,9 @@ def dm_permission(self) -> bool:

@property
def qualified_name(self) -> str:
""":class:`str`: The full command name, including parent names in the case of slash subcommands or groups.
For example, the qualified name for ``/one two three`` would be ``one two three``.
"""
return self.name

@property
Expand Down
23 changes: 0 additions & 23 deletions disnake/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,6 @@ class Bot(BotBase, InteractionBotBase, disnake.Client):
.. versionadded:: 2.6
sync_commands: :class:`bool`
Whether to enable automatic synchronization of application commands in your code.
Defaults to ``True``, which means that commands in API are automatically synced
with the commands in your code.
.. versionadded:: 2.1
sync_commands_on_cog_unload: :class:`bool`
Whether to sync the application commands on cog unload / reload. Defaults to ``True``.
.. versionadded:: 2.1
sync_commands_debug: :class:`bool`
Whether to always show sync debug logs (uses ``INFO`` log level if it's enabled, prints otherwise).
If disabled, uses the default ``DEBUG`` log level which isn't shown unless the log level is changed manually.
Useful for tracking the commands being registered in the API.
Defaults to ``False``.
.. versionadded:: 2.1
.. versionchanged:: 2.4
Changes the log level of corresponding messages from ``DEBUG`` to ``INFO`` or ``print``\\s them,
instead of controlling whether they are enabled at all.
reload: :class:`bool`
Whether to enable automatic extension reloading on file modification for debugging.
Whenever you save an extension with reloading enabled the file will be automatically
Expand Down
14 changes: 6 additions & 8 deletions disnake/ext/commands/ctx_menus_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,10 @@ def __init__(

@property
def type(self) -> Literal[ApplicationCommandType.user]:
return ApplicationCommandType.user
""":class:`ApplicationCommandType`: The type of this command.
@property
def qualified_name(self) -> str:
return self.name
Always returns :attr:`ApplicationCommandType.user`."""
return ApplicationCommandType.user

@property
def name_localizations(self) -> LocalizationValue:
Expand Down Expand Up @@ -249,11 +248,10 @@ def __init__(

@property
def type(self) -> Literal[ApplicationCommandType.message]:
return ApplicationCommandType.message
""":class:`ApplicationCommandType`: The type of this command.
@property
def qualified_name(self) -> str:
return self.name
Always returns :attr:`ApplicationCommandType.message`."""
return ApplicationCommandType.message

@property
def name_localizations(self) -> LocalizationValue:
Expand Down
2 changes: 2 additions & 0 deletions disnake/ext/commands/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ class CommandRegistrationError(ClientException):
The command name that had the error.
alias_conflict: :class:`bool`
Whether the name that conflicts is an alias of the command we try to add.
guild_id: Optional[:class:`int`]
The specific guild ID this command conflicts with, if any.
"""

def __init__(self, name: str, *, alias_conflict: bool = False, guild_id: int = None) -> None:
Expand Down
40 changes: 28 additions & 12 deletions disnake/ext/commands/interaction_bot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,10 @@ def __init__(

self._schedule_app_command_preparation()

def application_commands_iterator(self) -> Iterable[InvokableApplicationCommand]:
return chain(
self._all_app_commands.values(),
)

@property
def all_app_commands(self) -> List[InvokableApplicationCommand]:
return list(self._all_app_commands.values())

@property
def application_commands(self) -> Set[InvokableApplicationCommand]:
"""Set[:class:`InvokableApplicationCommand`]: A set of all application commands the bot has."""
return set(self.application_commands_iterator())
return set(self._all_app_commands.values())

@property
def slash_commands(self) -> Set[InvokableSlashCommand]:
Expand Down Expand Up @@ -404,6 +395,10 @@ def remove_slash_command(
----------
name: :class:`str`
The name of the slash command to remove.
guild_id: :class:`int`
The guild to remove the command from, if any.
.. versionadded:: 2.6
Returns
-------
Expand Down Expand Up @@ -433,6 +428,10 @@ def remove_user_command(
----------
name: :class:`str`
The name of the user command to remove.
guild_id: :class:`int`
The guild to remove the command from, if any.
.. versionadded:: 2.6
Returns
-------
Expand All @@ -455,6 +454,10 @@ def remove_message_command(
----------
name: :class:`str`
The name of the message command to remove.
guild_id: :class:`int`
The guild to remove the command from, if any.
.. versionadded:: 2.6
Returns
-------
Expand Down Expand Up @@ -488,6 +491,7 @@ def get_app_command(
def get_app_command(
self, name: str, type: ApplicationCommandType, *, guild_id: int = None
) -> Optional[InvokableApplicationCommand]:
# todo: document this method?
# this does not get commands by ID, use (some other method) to do that
if not isinstance(name, str):
raise TypeError(f"Expected name to be str, not {name.__class__}")
Expand All @@ -510,6 +514,10 @@ def get_slash_command(
----------
name: :class:`str`
The name of the slash command to get.
guild_id: :class:`int`
The guild_id to get the command from, if any.
.. versionadded:: 2.6
Raises
------
Expand Down Expand Up @@ -548,6 +556,10 @@ def get_user_command(
----------
name: :class:`str`
The name of the user command to get.
guild_id: :class:`int`
The guild_id to get the command from, if any.
.. versionadded:: 2.6
Returns
-------
Expand All @@ -566,6 +578,10 @@ def get_message_command(
----------
name: :class:`str`
The name of the message command to get.
guild_id: :class:`int`
The guild_id to get the command from, if any.
.. versionadded:: 2.6
Returns
-------
Expand Down Expand Up @@ -830,7 +846,7 @@ def _ordered_unsynced_commands(
global_cmds = []
guilds = {}

for cmd in self.application_commands_iterator():
for cmd in self._all_app_commands.values():
if not cmd.auto_sync:
cmd.body._always_synced = True

Expand Down Expand Up @@ -870,7 +886,7 @@ async def _cache_application_commands(self) -> None:
except (disnake.HTTPException, TypeError):
pass
else:
for command in self.application_commands_iterator():
for command in self._all_app_commands.values():
if command.body.id is not None and command.body.id not in global_commands:
command.body.id = None

Expand Down
Loading

0 comments on commit e39bffc

Please sign in to comment.