Skip to content
This repository was archived by the owner on Dec 18, 2021. It is now read-only.

Commit 67c53e2

Browse files
committed
feat: add disable_components to interaction
1 parent 9e791c5 commit 67c53e2

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

discord_components/component.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,8 @@ def disable(component: Component):
457457
component.disabled = True
458458
return component
459459

460-
disabled_row = list(map(disable, self._components))
461-
self._components = disabled_row
462-
return disabled_row
460+
self._components = list(map(disable, self._components))
461+
return self
463462

464463
def __list__(self) -> List[Component]:
465464
return self.components

discord_components/dpy_overrides.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ def get_component(self, custom_id: str) -> Optional[Component]:
4040
return component
4141

4242
async def disable_components(self) -> None:
43-
disabled_components = [row.disable_components() for row in self.components]
4443
await self.edit(
45-
components=disabled_components,
44+
components=[row.disable_components() for row in self.components],
4645
)
4746

4847
async def edit(
@@ -67,9 +66,7 @@ async def edit(
6766
data["content"] = content
6867

6968
if embed is not None and embeds is not None:
70-
raise InvalidArgument(
71-
"cannot pass both embed and embeds parameter to edit()"
72-
)
69+
raise InvalidArgument("cannot pass both embed and embeds parameter to edit()")
7370

7471
if embed is not None:
7572
data["embeds"] = [embed.to_dict()]
@@ -83,16 +80,11 @@ async def edit(
8380
data["flags"] = flags.value
8481

8582
if allowed_mentions is None:
86-
if (
87-
state.allowed_mentions is not None
88-
and self.author.id == self._state.self_id
89-
):
83+
if state.allowed_mentions is not None and self.author.id == self._state.self_id:
9084
data["allowed_mentions"] = state.allowed_mentions.to_dict()
9185
else:
9286
if state.allowed_mentions is not None:
93-
data["allowed_mentions"] = state.allowed_mentions.merge(
94-
allowed_mentions
95-
).to_dict()
87+
data["allowed_mentions"] = state.allowed_mentions.merge(allowed_mentions).to_dict()
9688
else:
9789
data["allowed_mentions"] = allowed_mentions.to_dict()
9890

@@ -253,9 +245,7 @@ async def send(
253245

254246
elif embeds is not None:
255247
if len(embeds) > 10:
256-
raise InvalidArgument(
257-
"embeds parameter must be a list of up to 10 elements"
258-
)
248+
raise InvalidArgument("embeds parameter must be a list of up to 10 elements")
259249
embeds = [embed.to_dict() for embed in embeds]
260250

261251
if stickers is not None:

discord_components/interaction.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,8 @@ async def edit_origin(
258258
return res
259259
elif res is not None:
260260
await res.delete(delay=delete_after)
261+
262+
async def disable_components(self) -> None:
263+
await self.edit_origin(
264+
components=[row.disable_components() for row in self.message.components],
265+
)

0 commit comments

Comments
 (0)