mirror of
https://github.com/Paillat-dev/pycord-reactive-views.git
synced 2026-01-02 01:06:18 +00:00
✨ Add option to edit view response in send method
This commit is contained in:
@@ -20,7 +20,13 @@ class ReactiveView(discord.ui.View):
|
|||||||
) -> None:
|
) -> None:
|
||||||
super().__init__(timeout=timeout, disable_on_timeout=disable_on_timeout) # pyright: ignore[reportUnknownMemberType]
|
super().__init__(timeout=timeout, disable_on_timeout=disable_on_timeout) # pyright: ignore[reportUnknownMemberType]
|
||||||
self._reactives: list[Reactive] = []
|
self._reactives: list[Reactive] = []
|
||||||
self.ctx: discord.ApplicationContext | discord.Interaction | discord.WebhookMessage | None = None
|
self.ctx: (
|
||||||
|
discord.InteractionMessage
|
||||||
|
| discord.ApplicationContext
|
||||||
|
| discord.Interaction
|
||||||
|
| discord.WebhookMessage
|
||||||
|
| None
|
||||||
|
) = None
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def add_item(self, item: discord.ui.Item[Self]) -> None:
|
def add_item(self, item: discord.ui.Item[Self]) -> None:
|
||||||
@@ -57,12 +63,17 @@ class ReactiveView(discord.ui.View):
|
|||||||
kwargs["embeds"] = embeds
|
kwargs["embeds"] = embeds
|
||||||
await editable.edit(**kwargs) # pyright: ignore[reportUnknownMemberType]
|
await editable.edit(**kwargs) # pyright: ignore[reportUnknownMemberType]
|
||||||
|
|
||||||
async def send(self, ctx: discord.ApplicationContext | discord.Interaction, ephemeral: bool = False) -> None:
|
async def send(
|
||||||
|
self, ctx: discord.ApplicationContext | discord.Interaction, ephemeral: bool = False, edit: bool = False
|
||||||
|
) -> None:
|
||||||
"""Send the view to a context."""
|
"""Send the view to a context."""
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
kwargs: dict[str, Any] = {"content": await self._get_content(), "ephemeral": ephemeral, "view": self} # pyright: ignore[reportExplicitAny]
|
kwargs: dict[str, Any] = {"content": await self._get_content(), "ephemeral": ephemeral, "view": self} # pyright: ignore[reportExplicitAny]
|
||||||
if embeds := await self._get_embeds():
|
if embeds := await self._get_embeds():
|
||||||
kwargs["embeds"] = embeds
|
kwargs["embeds"] = embeds
|
||||||
r = await ctx.respond(**kwargs) # pyright: ignore[reportUnknownMemberType]
|
if edit:
|
||||||
|
r = await ctx.edit(**kwargs) # pyright: ignore[reportUnknownMemberType]
|
||||||
|
else:
|
||||||
|
r = await ctx.respond(**kwargs) # pyright: ignore[reportUnknownMemberType]
|
||||||
if isinstance(ctx, discord.Interaction):
|
if isinstance(ctx, discord.Interaction):
|
||||||
self.ctx = r
|
self.ctx = r
|
||||||
|
|||||||
Reference in New Issue
Block a user