Skip to content

Commit

Permalink
[ext.pages] Fix for "Unknown Message" errors when using ephemeral pag…
Browse files Browse the repository at this point in the history
…inators (#1224)

* fix for "Unknown Message" errors when using an ephemeral paginator after an ephemeral defer

* spelling error
  • Loading branch information
krittick authored Apr 3, 2022
1 parent 1eebe96 commit e93ecca
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,11 @@ async def respond(
ephemeral: :class:`bool`
Whether the paginator message and its components are ephemeral.
If ``target`` is specified, the ephemeral message content will be ``target_message`` instead.
.. warning::
If your paginator is ephemeral, it cannot have a timeout longer than 15 minutes (and cannot be persistent).
target: Optional[:class:`~discord.abc.Messageable`]
A target where the paginated message should be sent, if different from the original :class:`discord.Interaction`
target_message: :class:`str`
Expand All @@ -775,7 +780,7 @@ async def respond(
if target is not None and not isinstance(target, discord.abc.Messageable):
raise TypeError(f"expected abc.Messageable not {target.__class__!r}")

if ephemeral and self.timeout >= 900 or self.timeout is None:
if ephemeral and (self.timeout >= 900 or self.timeout is None):
raise ValueError(
"paginator responses cannot be ephemeral if the paginator timeout is 15 minutes or greater"
)
Expand All @@ -801,18 +806,17 @@ async def respond(
view=self,
ephemeral=ephemeral,
)
# convert from WebhookMessage to Message reference to bypass 15min webhook token timeout
msg = await msg.channel.fetch_message(msg.id)
# convert from WebhookMessage to Message reference to bypass 15min webhook token timeout (non-ephemeral messages only)
if not ephemeral:
msg = await msg.channel.fetch_message(msg.id)
else:
msg = await interaction.response.send_message(
content=page_content.content,
embeds=page_content.embeds,
view=self,
ephemeral=ephemeral,
)
if isinstance(msg, discord.WebhookMessage):
self.message = await msg.channel.fetch_message(msg.id)
elif isinstance(msg, discord.Message):
if isinstance(msg, (discord.Message, discord.WebhookMessage)):
self.message = msg
elif isinstance(msg, discord.Interaction):
self.message = await msg.original_message()
Expand Down

0 comments on commit e93ecca

Please sign in to comment.