Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Paginator fixes for disable(), cancel(), and respond methods. #1088

Merged
merged 9 commits into from
Mar 3, 2022
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 @@ -701,18 +701,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