Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(i18n): change localization attributes' defaults #1866

Merged
Merged
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ These changes are available on the `master` branch, but have not yet been releas

- Added possibility to start bot via async context manager.
([#1801](https://github.com/Pycord-Development/pycord/pull/1801))
- Change default for all `name_localizations` & `description_localizations` attributes
from being `None` to be `MISSING`.
([#1866](https://github.com/Pycord-Development/pycord/pull/1866))
- Added new parameters (`author`, `footer`, `image`, `thumbnail`) to `discord.Embed`.
([#1996](https://github.com/Pycord-Development/pycord/pull/1996))
- Added new events `on_bridge_command`, `on_bridge_command_completion`, and
Expand Down
44 changes: 22 additions & 22 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,10 @@ class SlashCommand(ApplicationCommand):
cooldown: Optional[:class:`~discord.ext.commands.Cooldown`]
The cooldown applied when the command is invoked. ``None`` if the command
doesn't have a cooldown.
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
name_localizations: Dict[:class:`str`, :class:`str`]
The name localizations for this command. The values of this should be ``"locale": "name"``. See
`here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
description_localizations: Optional[Dict[:class:`str`, :class:`str`]]
description_localizations: Dict[:class:`str`, :class:`str`]
The description localizations for this command. The values of this should be ``"locale": "description"``.
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
"""
Expand All @@ -668,8 +668,8 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
raise TypeError("Callback must be a coroutine.")
self.callback = func

self.name_localizations: dict[str, str] | None = kwargs.get(
"name_localizations", None
self.name_localizations: dict[str, str] = kwargs.get(
"name_localizations", MISSING
)
_validate_names(self)

Expand All @@ -680,8 +680,8 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
)

self.description: str = description
self.description_localizations: dict[str, str] | None = kwargs.get(
"description_localizations", None
self.description_localizations: dict[str, str] = kwargs.get(
"description_localizations", MISSING
)
_validate_descriptions(self)

Expand Down Expand Up @@ -843,9 +843,9 @@ def to_dict(self) -> dict:
"description": self.description,
"options": [o.to_dict() for o in self.options],
}
if self.name_localizations is not None:
if self.name_localizations is not MISSING:
as_dict["name_localizations"] = self.name_localizations
if self.description_localizations is not None:
if self.description_localizations is not MISSING:
as_dict["description_localizations"] = self.description_localizations
if self.is_subcommand:
as_dict["type"] = SlashCommandOptionType.sub_command.value
Expand Down Expand Up @@ -1081,10 +1081,10 @@ class SlashCommandGroup(ApplicationCommand):
:exc:`.ApplicationCommandError` should be used. Note that if the checks fail then
:exc:`.CheckFailure` exception is raised to the :func:`.on_application_command_error`
event.
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
name_localizations: Dict[:class:`str`, :class:`str`]
The name localizations for this command. The values of this should be ``"locale": "name"``. See
`here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
description_localizations: Optional[Dict[:class:`str`, :class:`str`]]
description_localizations: Dict[:class:`str`, :class:`str`]
The description localizations for this command. The values of this should be ``"locale": "description"``.
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
"""
Expand Down Expand Up @@ -1146,11 +1146,11 @@ def __init__(
self.guild_only: bool | None = kwargs.get("guild_only", None)
self.nsfw: bool | None = kwargs.get("nsfw", None)

self.name_localizations: dict[str, str] | None = kwargs.get(
"name_localizations", None
self.name_localizations: dict[str, str] = kwargs.get(
"name_localizations", MISSING
)
self.description_localizations: dict[str, str] | None = kwargs.get(
"description_localizations", None
self.description_localizations: dict[str, str] = kwargs.get(
"description_localizations", MISSING
)

@property
Expand All @@ -1163,9 +1163,9 @@ def to_dict(self) -> dict:
"description": self.description,
"options": [c.to_dict() for c in self.subcommands],
}
if self.name_localizations is not None:
if self.name_localizations is not MISSING:
as_dict["name_localizations"] = self.name_localizations
if self.description_localizations is not None:
if self.description_localizations is not MISSING:
as_dict["description_localizations"] = self.description_localizations

if self.parent is not None:
Expand Down Expand Up @@ -1236,10 +1236,10 @@ def create_subgroup(
:exc:`.ApplicationCommandError` should be used. Note that if the checks fail then
:exc:`.CheckFailure` exception is raised to the :func:`.on_application_command_error`
event.
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
name_localizations: Dict[:class:`str`, :class:`str`]
The name localizations for this command. The values of this should be ``"locale": "name"``. See
`here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
description_localizations: Optional[Dict[:class:`str`, :class:`str`]]
description_localizations: Dict[:class:`str`, :class:`str`]
The description localizations for this command. The values of this should be ``"locale": "description"``.
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.

Expand Down Expand Up @@ -1413,7 +1413,7 @@ class ContextMenuCommand(ApplicationCommand):
cooldown: Optional[:class:`~discord.ext.commands.Cooldown`]
The cooldown applied when the command is invoked. ``None`` if the command
doesn't have a cooldown.
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
name_localizations: Dict[:class:`str`, :class:`str`]
The name localizations for this command. The values of this should be ``"locale": "name"``. See
`here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
"""
Expand All @@ -1430,8 +1430,8 @@ def __init__(self, func: Callable, *args, **kwargs) -> None:
raise TypeError("Callback must be a coroutine.")
self.callback = func

self.name_localizations: dict[str, str] | None = kwargs.get(
"name_localizations", None
self.name_localizations: dict[str, str] = kwargs.get(
"name_localizations", MISSING
)

# Discord API doesn't support setting descriptions for context menu commands, so it must be empty
Expand Down Expand Up @@ -1506,7 +1506,7 @@ def to_dict(self) -> dict[str, str | int]:
"default_member_permissions"
] = self.default_member_permissions.value

if self.name_localizations is not None:
if self.name_localizations:
as_dict["name_localizations"] = self.name_localizations

return as_dict
Expand Down
21 changes: 12 additions & 9 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from ..enums import ChannelType
from ..enums import Enum as DiscordEnum
from ..enums import SlashCommandOptionType
from ..utils import MISSING

if TYPE_CHECKING:
from ..ext.commands import Converter
Expand Down Expand Up @@ -152,10 +153,10 @@ class Option:
A list of channel types that can be selected in this option.
Only applies to Options with an :attr:`input_type` of :class:`discord.SlashCommandOptionType.channel`.
If this argument is used, :attr:`input_type` will be ignored.
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
name_localizations: Dict[:class:`str`, :class:`str`]
The name localizations for this option. The values of this should be ``"locale": "name"``.
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
description_localizations: Optional[Dict[:class:`str`, :class:`str`]]
description_localizations: Dict[:class:`str`, :class:`str`]
The description localizations for this option. The values of this should be ``"locale": "description"``.
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.

Expand Down Expand Up @@ -323,8 +324,10 @@ def __init__(

self.autocomplete = kwargs.pop("autocomplete", None)

self.name_localizations = kwargs.pop("name_localizations", None)
self.description_localizations = kwargs.pop("description_localizations", None)
self.name_localizations = kwargs.pop("name_localizations", MISSING)
self.description_localizations = kwargs.pop(
"description_localizations", MISSING
)

def to_dict(self) -> dict:
as_dict = {
Expand All @@ -335,9 +338,9 @@ def to_dict(self) -> dict:
"choices": [c.to_dict() for c in self.choices],
"autocomplete": bool(self.autocomplete),
}
if self.name_localizations is not None:
if self.name_localizations is not MISSING:
as_dict["name_localizations"] = self.name_localizations
if self.description_localizations is not None:
if self.description_localizations is not MISSING:
as_dict["description_localizations"] = self.description_localizations
if self.channel_types:
as_dict["channel_types"] = [t.value for t in self.channel_types]
Expand Down Expand Up @@ -368,7 +371,7 @@ class OptionChoice:
The name of the choice. Shown in the UI when selecting an option.
value: Optional[Union[:class:`str`, :class:`int`, :class:`float`]]
The value of the choice. If not provided, will use the value of ``name``.
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
name_localizations: Dict[:class:`str`, :class:`str`]
The name localizations for this choice. The values of this should be ``"locale": "name"``.
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
"""
Expand All @@ -377,15 +380,15 @@ def __init__(
self,
name: str,
value: str | int | float | None = None,
name_localizations: dict[str, str] | None = None,
name_localizations: dict[str, str] = MISSING,
):
self.name = str(name)
self.value = value if value is not None else name
self.name_localizations = name_localizations

def to_dict(self) -> dict[str, str | int | float]:
as_dict = {"name": self.name, "value": self.value}
if self.name_localizations is not None:
if self.name_localizations is not MISSING:
as_dict["name_localizations"] = self.name_localizations

return as_dict
Expand Down