Repository: Pycord-Development/pycord

Issue:
Add a way to pass an interaction for a paginator to update
### Summary

Addition of a way to pass an existing interaction for a paginator to update

### What is the feature request for?

discord.ext.pages

### The Problem

Currently, I don't know of a clean and simple way to tell a paginator to update an existing interaction as opposed to sending the paginator as a new response, as in the following scenario:

```py
if condition:
  initial = await ctx.respond(embed=some_embed, view=some_view)
else:
  initial = None

if initial:
"""
Edit initial to be the paginator. So replace its embeds, message content, view, etc. as if it was a totally new response, but its editing the existing interaction
"""
else:
  await paginator.respond(ctx.interaction)
```

### The Ideal Solution

To be able to pass in an interaction for the paginator to edit

### The Current Solution

I was able to replicate the functionality I want by doing the following:
```py
if initial:
    paginator.user = ctx.author
    paginator.message = await initial.original_message()
    paginator.update_buttons()
    embed = paginator.pages[paginator.current_page]
    embed = paginator.get_page_content(embed)
    await initial.edit_original_message(view=paginator, embeds=embed)
else:
    await paginator.respond(ctx.interaction)
```

### Additional Context

_No response_


Discussion:

Resolving patch:
diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py
--- a/discord/ext/pages/pagination.py
+++ b/discord/ext/pages/pagination.py
@@ -839,6 +839,70 @@ async def send(
 
         return self.message
 
+    async def edit(
+        self,
+        message: discord.Message,
+        suppress: Optional[bool] = None,
+        allowed_mentions: Optional[discord.AllowedMentions] = None,
+        delete_after: Optional[float] = None,
+    ) -> Optional[discord.Message]:
+        """Edits an existing message to replace it with the paginator contents.
+
+        .. note::
+
+            If invoked from an interaction, you will still need to respond to the interaction.
+
+
+        Parameters
+        -----------
+        message: :class:`discord.Message`
+            The message to edit with the paginator.
+        suppress: :class:`bool`
+            Whether to suppress embeds for the message. This removes
+            all the embeds if set to ``True``. If set to ``False``
+            this brings the embeds back if they were suppressed.
+            Using this parameter requires :attr:`~.Permissions.manage_messages`.
+        allowed_mentions: Optional[:class:`~discord.AllowedMentions`]
+            Controls the mentions being processed in this message. If this is
+            passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`.
+            The merging behaviour only overrides attributes that have been explicitly passed
+            to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
+            If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
+            are used instead.
+        delete_after: Optional[:class:`float`]
+            If set, deletes the paginator after the specified time.
+
+        Returns
+        --------
+        Optional[:class:`discord.Message`]
+            The message that was edited. Returns ``None`` if the operation failed.
+        """
+        if not isinstance(message, discord.Message):
+            raise TypeError(f"expected Message not {message.__class__!r}")
+
+        self.update_buttons()
+
+        page: Union[Page, str, discord.Embed, List[discord.Embed]] = self.pages[self.current_page]
+        page_content: Page = self.get_page_content(page)
+
+        if page_content.custom_view:
+            self.update_custom_view(page_content.custom_view)
+
+        self.user = message.author
+        try:
+            self.message = await message.edit(
+                content=page_content.content,
+                embeds=page_content.embeds,
+                view=self,
+                suppress=suppress,
+                allowed_mentions=allowed_mentions,
+                delete_after=delete_after,
+            )
+        except (discord.NotFound, discord.Forbidden):
+            pass
+
+        return self.message
+
     async def respond(
         self,
         interaction: discord.Interaction,


Test patch: