Repository: hikari-py/hikari
Pull request #1266 (2022-08-22 08:48:34)

Add `replace_attachments` kwarg for `RESTClient.create_initial_response`.
### Summary
<!-- Small summary of the merge request -->
Allows `replace_attachments` kwarg to be used for `RESTClient.create_initial_response`. This is required to remove attachments when responding to a component interaction.


### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [ ] I have run `nox` and all the pipelines have passed.
- [x] I have made unittests according to the code I have added/modified/deleted.

Nox reformat-code and slotscheck pipelines fail on something I didn't change in this PR.

### Related issues
<!--
To mention an issue use `#issue-id` and to mention a merge request use `!merge-request-id`
To close/fix an issue use `Close #issue-id` or `Fix #issue-id` (depending on the merge request)
-->


davfsa: I'm going to hold off on this one, as it might not be necessary if we can update to v10 before.

Note to self, allow this in #1260

Patch:
diff --git a/changes/1266.bugfix.md b/changes/1266.bugfix.md
new file mode 100644
index 00000000..e63c56ff
--- /dev/null
+++ b/changes/1266.bugfix.md
@@ -0,0 +1,1 @@
+Allow for `replace_attachments` kwarg to be used in `RESTClient.create_initial_response`.
diff --git a/dev-requirements/build.txt b/dev-requirements/build.txt
index df9bce98..0f8168c8 100644
--- a/dev-requirements/build.txt
+++ b/dev-requirements/build.txt
@@ -1,2 +1,2 @@
-setuptools~=65.1.0
+setuptools>=65.2.0
 wheel==0.37.1
diff --git a/hikari/api/rest.py b/hikari/api/rest.py
index 1221dd8f..26d154e8 100644
--- a/hikari/api/rest.py
+++ b/hikari/api/rest.py
@@ -7411,6 +7411,7 @@ async def create_interaction_response(
         components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED,
         embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED,
         embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED,
+        replace_attachments: bool = False,
         mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
         user_mentions: undefined.UndefinedOr[
             typing.Union[snowflakes.SnowflakeishSequence[users.PartialUser], bool]
@@ -7463,6 +7464,11 @@ async def create_interaction_response(
             If provided, the message embed.
         embeds : hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]]
             If provided, the message embeds.
+        replace_attachments: bool
+            Whether to replace the attachments with the provided ones. Defaults
+            to `builtins.False`. This only effects component interactions.
+
+            Note this will also overwrite the embed attachments.
         flags : typing.Union[builtins.int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType]
             If provided, the message flags this response should have.
 
diff --git a/hikari/impl/rest.py b/hikari/impl/rest.py
index 054de53b..d1a255f0 100644
--- a/hikari/impl/rest.py
+++ b/hikari/impl/rest.py
@@ -3444,6 +3444,7 @@ async def create_interaction_response(
         components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED,
         embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED,
         embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED,
+        replace_attachments: bool = False,
         mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
         user_mentions: undefined.UndefinedOr[
             typing.Union[snowflakes.SnowflakeishSequence[users.PartialUser], bool]
@@ -3462,6 +3463,7 @@ async def create_interaction_response(
             components=components,
             embed=embed,
             embeds=embeds,
+            replace_attachments=replace_attachments,
             tts=tts,
             flags=flags,
             mentions_everyone=mentions_everyone,
diff --git a/hikari/interactions/base_interactions.py b/hikari/interactions/base_interactions.py
index 08019661..6eb22fd4 100644
--- a/hikari/interactions/base_interactions.py
+++ b/hikari/interactions/base_interactions.py
@@ -249,6 +249,7 @@ async def create_initial_response(
         components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED,
         embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED,
         embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED,
+        replace_attachments: bool = False,
         mentions_everyone: undefined.UndefinedOr[bool] = undefined.UNDEFINED,
         user_mentions: undefined.UndefinedOr[
             typing.Union[snowflakes.SnowflakeishSequence[users.PartialUser], bool]
@@ -296,6 +297,11 @@ async def create_initial_response(
             If provided, the message embed.
         embeds : hikari.undefined.UndefinedOr[typing.Sequence[hikari.embeds.Embed]]
             If provided, the message embeds.
+        replace_attachments: bool
+            Whether to replace the attachments with the provided ones. Defaults
+            to `builtins.False`. This only effects component interactions.
+
+            Note this will also overwrite the embed attachments.
         flags : typing.Union[builtins.int, hikari.messages.MessageFlag, hikari.undefined.UndefinedType]
             If provided, the message flags this response should have.
 
@@ -367,6 +373,7 @@ async def create_initial_response(
             components=components,
             embed=embed,
             embeds=embeds,
+            replace_attachments=replace_attachments,
             flags=flags,
             mentions_everyone=mentions_everyone,
             user_mentions=user_mentions,


Test patch:
diff --git a/tests/hikari/impl/test_rest.py b/tests/hikari/impl/test_rest.py
index 47febacb..4d7dd278 100644
--- a/tests/hikari/impl/test_rest.py
+++ b/tests/hikari/impl/test_rest.py
@@ -5099,6 +5099,7 @@ async def test_create_interaction_response_when_form(self, rest_client):
             components=[component_obj2],
             embed=embed_obj,
             embeds=[embed_obj2],
+            replace_attachments=True,
             tts=True,
             flags=120,
             mentions_everyone=False,
@@ -5114,6 +5115,7 @@ async def test_create_interaction_response_when_form(self, rest_client):
             components=[component_obj2],
             embed=embed_obj,
             embeds=[embed_obj2],
+            replace_attachments=True,
             tts=True,
             flags=120,
             mentions_everyone=False,
@@ -5149,6 +5151,7 @@ async def test_create_interaction_response_when_no_form(self, rest_client):
             components=[component_obj2],
             embed=embed_obj,
             embeds=[embed_obj2],
+            replace_attachments=True,
             tts=True,
             flags=120,
             mentions_everyone=False,
@@ -5164,6 +5167,7 @@ async def test_create_interaction_response_when_no_form(self, rest_client):
             components=[component_obj2],
             embed=embed_obj,
             embeds=[embed_obj2],
+            replace_attachments=True,
             tts=True,
             flags=120,
             mentions_everyone=False,
diff --git a/tests/hikari/interactions/test_base_interactions.py b/tests/hikari/interactions/test_base_interactions.py
index 16f92862..364e58f9 100644
--- a/tests/hikari/interactions/test_base_interactions.py
+++ b/tests/hikari/interactions/test_base_interactions.py
@@ -87,6 +87,7 @@ async def test_create_initial_response_with_optional_args(self, mock_message_res
             components=mock_components,
             attachment=mock_attachment,
             attachments=mock_attachments,
+            replace_attachments=True,
             mentions_everyone=False,
             user_mentions=[123432],
             role_mentions=[6324523],
@@ -105,6 +106,7 @@ async def test_create_initial_response_with_optional_args(self, mock_message_res
             components=mock_components,
             attachment=mock_attachment,
             attachments=mock_attachments,
+            replace_attachments=True,
             mentions_everyone=False,
             user_mentions=[123432],
             role_mentions=[6324523],
@@ -129,6 +131,7 @@ async def test_create_initial_response_without_optional_args(self, mock_message_
             components=undefined.UNDEFINED,
             attachment=undefined.UNDEFINED,
             attachments=undefined.UNDEFINED,
+            replace_attachments=False,
             mentions_everyone=undefined.UNDEFINED,
             user_mentions=undefined.UNDEFINED,
             role_mentions=undefined.UNDEFINED,