Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
feat: confirm before opening help thread
Browse files Browse the repository at this point in the history
  • Loading branch information
VaibhavSys committed May 4, 2024
1 parent b1212c3 commit 2e64868
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/exts/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ def __init__(self, label: str, link: str):
)


class ConfirmView(nextcord.ui.View):
def __init__(self):
super().__init__()
self.value = None

@nextcord.ui.button(label="Confirm", style=nextcord.ButtonStyle.green)
async def confirm(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
await interaction.send("Confirming...", ephemeral=True)
self.value = True
self.stop()

@nextcord.ui.button(label="Cancel", style=nextcord.ButtonStyle.grey)
async def cancel(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
await interaction.send("Cancelling...", ephemeral=True)
self.value = False
self.stop()


class OpenHelpView(nextcord.ui.View):
def __init__(self, open_help_func: callable):
super().__init__(timeout=None)
Expand All @@ -27,6 +49,17 @@ async def open_help(
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
):
await interaction.response.defer(ephemeral=True)
confirm_view = ConfirmView()
await interaction.send(
"Are you sure you want to open a help thread?", view=confirm_view
)
await confirm_view.wait()
if confirm_view.value is None:
await interaction.send("Timed out.", ephemeral=True)
return
elif not confirm_view.value:
await interaction.send("Cancelled.", ephemeral=True)
return
thread: nextcord.Thread = await self.open_help_func(interaction.user)
await interaction.send(f"Created help thread {thread.mention}.", ephemeral=True)

Expand Down

0 comments on commit 2e64868

Please sign in to comment.