diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca446e162..f7dbc841dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,7 @@ Bugfixes - `is_webhook` will now return `undefined.UNDEFINED` if the information is not available - Fix logic in `is_human` to account for the changes in the typing - Set `PartialMessage.member` to `undefined.UNDEFINED` when Discord edit the message to display an embed/attachment ([#783](https://github.com/hikari-py/hikari/issues/783)) -- `CommandOption.value` will now be cast to a `Snowflake` for types 6-9 ([#785](https://github.com/hikari-py/hikari/issues/785)) +- `CommandInteractionOption.value` will now be cast to a `Snowflake` for types 6-9 ([#785](https://github.com/hikari-py/hikari/issues/785)) Improved Documentation diff --git a/changes/800.feature.md b/changes/800.feature.md new file mode 100644 index 0000000000..7adf3e8ef7 --- /dev/null +++ b/changes/800.feature.md @@ -0,0 +1 @@ +Support new `channel_types` field in `CommandOption` diff --git a/hikari/commands.py b/hikari/commands.py index cc42d5003b..b0f2f32677 100644 --- a/hikari/commands.py +++ b/hikari/commands.py @@ -44,6 +44,7 @@ from hikari.internal import enums if typing.TYPE_CHECKING: + from hikari import channels from hikari import guilds @@ -136,6 +137,14 @@ class CommandOption: options: typing.Optional[typing.Sequence[CommandOption]] = attr.field(default=None, repr=False) """Sequence of up to (and including) 25 of the options for this command option.""" + channel_types: typing.Optional[typing.Sequence[typing.Union[channels.ChannelType, int]]] = attr.field( + default=None, repr=False + ) + """The channel types that this option will accept. + + If `builtins.None`, then all channel types will be accepted. + """ + @attr_extensions.with_copy @attr.define(hash=True, kw_only=True, weakref_slot=False) diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py index d464b9999f..e5fb70079f 100644 --- a/hikari/impl/entity_factory.py +++ b/hikari/impl/entity_factory.py @@ -1669,6 +1669,10 @@ def _deserialize_command_option(self, payload: data_binding.JSONObject) -> comma if raw_options := payload.get("options"): suboptions = [self._deserialize_command_option(option) for option in raw_options] + channel_types: typing.Optional[typing.Sequence[typing.Union[channel_models.ChannelType, int]]] = None + if raw_channel_types := payload.get("channel_types"): + channel_types = [channel_models.ChannelType(channel_type) for channel_type in raw_channel_types] + return commands.CommandOption( type=commands.OptionType(payload["type"]), name=payload["name"], @@ -1676,6 +1680,7 @@ def _deserialize_command_option(self, payload: data_binding.JSONObject) -> comma is_required=payload.get("required", False), choices=choices, options=suboptions, + channel_types=channel_types, ) def deserialize_command( @@ -1889,6 +1894,9 @@ def serialize_command_option(self, option: commands.CommandOption) -> data_bindi "required": option.is_required, } + if option.channel_types is not None: + payload["channel_types"] = option.channel_types + if option.choices is not None: payload["choices"] = [{"name": choice.name, "value": choice.value} for choice in option.choices] diff --git a/hikari/messages.py b/hikari/messages.py index d79523acf1..4bc194c36d 100644 --- a/hikari/messages.py +++ b/hikari/messages.py @@ -608,7 +608,7 @@ class ButtonComponent(PartialComponent): """Custom or unicode emoji which appears on the button.""" custom_id: typing.Optional[str] = attr.field(hash=True) - """Developer defined identifier for this button (will be >= 100 characters). + """Developer defined identifier for this button (will be <= 100 characters). !!! note This is required for the following button styles: @@ -656,7 +656,7 @@ class SelectMenuComponent(PartialComponent): """ custom_id: str = attr.field(hash=True) - """Developer defined identifier for this menu (will be >= 100 characters).""" + """Developer defined identifier for this menu (will be <= 100 characters).""" options: typing.Sequence[SelectMenuOption] = attr.field(eq=False) """Sequence of up to 25 of the options set for this menu.""" diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py index 90dcc97c9c..5b47d35682 100644 --- a/tests/hikari/impl/test_entity_factory.py +++ b/tests/hikari/impl/test_entity_factory.py @@ -3091,6 +3091,25 @@ def test_deserialize_interaction_handles_unknown_type(self, entity_factory_impl) with pytest.raises(errors.UnrecognisedEntityError): entity_factory_impl.deserialize_interaction({"type": -999}) + def test_serialize_command_option_with_channel_type(self, entity_factory_impl): + option = commands.CommandOption( + type=commands.OptionType.INTEGER, + name="a name", + description="go away", + is_required=True, + channel_types=[channel_models.ChannelType.GUILD_STAGE, channel_models.ChannelType.GUILD_TEXT, 100], + ) + + result = entity_factory_impl.serialize_command_option(option) + + assert result == { + "type": 4, + "name": "a name", + "description": "go away", + "required": True, + "channel_types": [13, 0, 100], + } + def test_serialize_command_option_with_choices(self, entity_factory_impl): option = commands.CommandOption( type=commands.OptionType.INTEGER,