Skip to content

Commit

Permalink
Various Paginator fixes for disable(), cancel(), and respond me…
Browse files Browse the repository at this point in the history
…thods. (Pycord-Development#1088)

* potential fix for Pycord-Development#1083 by converting WebhookMessage to Message

* fix for Pycord-Development#1082

* fix for Pycord-Development#1082

* proper fix for Pycord-Development#1083 by converting WebhookMessage and InteractionMessage to Message

* apply fix for Pycord-Development#1082 to `cancel()` method as well

* apply fix for Pycord-Development#1082 to `cancel()` method as well

* fix logic for cancel/disable
  • Loading branch information
krittick authored Mar 3, 2022
1 parent 0a1b6b0 commit 6474f26
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async def disable(
"""
page = self.get_page_content(page)
for item in self.children:
if item not in self.custom_view.children or include_custom:
if include_custom or not self.custom_view or item not in self.custom_view.children:
item.disabled = True
if page:
await self.message.edit(
Expand Down Expand Up @@ -402,7 +402,7 @@ async def cancel(
items = self.children.copy()
page = self.get_page_content(page)
for item in items:
if item not in self.custom_view.children or include_custom:
if include_custom or not self.custom_view or item not in self.custom_view.children:
self.remove_item(item)
if page:
await self.message.edit(
Expand Down Expand Up @@ -737,18 +737,22 @@ async def respond(
view=self,
ephemeral=ephemeral,
)

# convert from WebhookMessage to Message reference to bypass 15min webhook token timeout
msg = msg.channel.get_partial_message(msg.id) or await msg.channel.fetch_message(msg.id)
else:
msg = await interaction.response.send_message(
content=page if isinstance(page, str) else None,
embeds=[] if isinstance(page, str) else page,
view=self,
ephemeral=ephemeral,
)
if isinstance(msg, (discord.WebhookMessage, discord.Message)):
if isinstance(msg, discord.WebhookMessage):
self.message = await msg.channel.fetch_message(msg.id)
elif isinstance(msg, discord.Message):
self.message = msg
elif isinstance(msg, discord.Interaction):
self.message = await msg.original_message()
msg = await msg.original_message()
self.message = await msg.channel.fetch_message(msg.id)

return self.message

Expand Down

0 comments on commit 6474f26

Please sign in to comment.