Fix http errors for interaction deferring and message changes (#6229)

This commit is contained in:
Jakub Kuczys 2023-08-11 02:51:36 +02:00 committed by GitHub
parent dbb91dfce8
commit 100de11ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 11 deletions

View File

@ -37,6 +37,7 @@ class _GenericButton(discord.ui.Button):
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
@ -52,7 +53,6 @@ class _GenericButton(discord.ui.Button):
await self.func(ctx, pages, controls, message, page, timeout, emoji)
except Exception:
pass
await interaction.response.defer()
async def menu(

View File

@ -193,6 +193,7 @@ class SimpleMenu(discord.ui.View):
return self._source
async def on_timeout(self):
try:
if self.delete_after_timeout and not self.message.flags.ephemeral:
await self.message.delete()
elif self.disable_after_timeout:
@ -201,6 +202,9 @@ class SimpleMenu(discord.ui.View):
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
@ -523,9 +527,14 @@ class ConfirmView(discord.ui.View):
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):