aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2023-06-20 17:21:34 +0100
committerGravatar Chris Lovering <[email protected]>2023-06-23 09:08:10 +0100
commitb18570fb21fdfc039330a9556530af6f85d1a519 (patch)
tree050e692645a4c522ae9b0fcea965eb42fee726b8
parentRemove logic around when a role is available (diff)
Swap the order of interaction resposnes in sub cog
interaction.followup is only available after interaction.response is successfully used. Since interaction.response.edit_message can fail, using interaction.followup afterwards is incorrect. By swapping the order around here, we guarantee that a followup webhook is available.
-rw-r--r--bot/exts/info/subscribe.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/bot/exts/info/subscribe.py b/bot/exts/info/subscribe.py
index 48168aa1a..4f57f7c0f 100644
--- a/bot/exts/info/subscribe.py
+++ b/bot/exts/info/subscribe.py
@@ -94,8 +94,15 @@ class SingleRoleButton(discord.ui.Button):
)
self.assigned = not self.assigned
- await self.update_view(interaction)
- await interaction.followup.send(
+ try:
+ await self.update_view(interaction)
+ send_function = interaction.followup.send
+ except discord.NotFound:
+ log.debug("Subscribe message for %s removed before buttons could be updated", interaction.user)
+ self.view.stop()
+ send_function = interaction.response.send_message
+
+ await send_function(
self.LABEL_FORMAT.format(action="Added" if self.assigned else "Removed", role_name=self.role.name),
ephemeral=True,
)
@@ -104,11 +111,7 @@ class SingleRoleButton(discord.ui.Button):
"""Updates the original interaction message with a new view object with the updated buttons."""
self.style = self.REMOVE_STYLE if self.assigned else self.ADD_STYLE
self.label = self.LABEL_FORMAT.format(action="Remove" if self.assigned else "Add", role_name=self.role.name)
- try:
- await interaction.response.edit_message(view=self.view)
- except discord.NotFound:
- log.debug("Subscribe message for %s removed before buttons could be updated", interaction.user)
- self.view.stop()
+ await interaction.response.edit_message(view=self.view)
class AllSelfAssignableRolesView(discord.ui.View):