Skip to content

Commit

Permalink
Fix http errors for interaction deferring and message changes (#6229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackenmen authored Aug 11, 2023
1 parent dbb91df commit 100de11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion redbot/core/utils/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, emoji: discord.PartialEmoji, func: _ControlCallable):
self.func = func

async def callback(self, interaction: discord.Interaction):
await interaction.response.defer()
ctx = self.view.ctx
pages = self.view.source.entries
controls = None
Expand All @@ -52,7 +53,6 @@ async def callback(self, interaction: discord.Interaction):
await self.func(ctx, pages, controls, message, page, timeout, emoji)
except Exception:
pass
await interaction.response.defer()


async def menu(
Expand Down
29 changes: 19 additions & 10 deletions redbot/core/utils/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,18 @@ def source(self):
return self._source

async def on_timeout(self):
if self.delete_after_timeout and not self.message.flags.ephemeral:
await self.message.delete()
elif self.disable_after_timeout:
for child in self.children:
child.disabled = True
await self.message.edit(view=self)
else:
await self.message.edit(view=None)
try:
if self.delete_after_timeout and not self.message.flags.ephemeral:
await self.message.delete()
elif self.disable_after_timeout:
for child in self.children:
child.disabled = True
await self.message.edit(view=self)
else:
await self.message.edit(view=None)
except discord.HTTPException:
# message could no longer be there or we may not be able to edit/delete it anymore
pass

def _get_select_menu(self):
# handles modifying the select menu if more than 25 pages are provided
Expand Down Expand Up @@ -523,9 +527,14 @@ async def on_timeout(self):
if self.disable_buttons:
self.confirm_button.disabled = True
self.dismiss_button.disabled = True
await self.message.edit(view=self)
view = self
else:
await self.message.edit(view=None)
view = None
try:
await self.message.edit(view=view)
except discord.HTTPException:
# message could no longer be there or we may not be able to edit it anymore
pass

@discord.ui.button(label=_("Yes"), style=discord.ButtonStyle.green)
async def confirm_button(self, interaction: discord.Interaction, button: discord.ui.Button):
Expand Down

0 comments on commit 100de11

Please sign in to comment.