45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import discord
|
|
from discord import ui
|
|
|
|
|
|
# Define a simple View that gives us a confirmation menu
|
|
class Confirm(ui.View):
|
|
value: bool | None = None
|
|
|
|
@ui.button(label="Confirm", style=discord.ButtonStyle.green)
|
|
async def confirm(self, interaction: discord.Interaction, button: ui.Button):
|
|
await interaction.response.edit_message(content="Confirming", view=None)
|
|
self.value = True
|
|
self.stop()
|
|
|
|
@ui.button(label="Cancel", style=discord.ButtonStyle.grey)
|
|
async def cancel(self, interaction: discord.Interaction, button: ui.Button):
|
|
await interaction.response.edit_message(content="Cancelling", view=None)
|
|
self.value = False
|
|
self.stop()
|
|
|
|
|
|
class PostModal(ui.Modal, title="foobar2000"):
|
|
content = ui.TextInput(
|
|
label="Hier könnte Ihre Werbung stehen",
|
|
style=discord.TextStyle.long,
|
|
)
|
|
|
|
async def on_submit(self, interaction: discord.Interaction):
|
|
view = Confirm()
|
|
|
|
await interaction.response.send_message(
|
|
content=f"## Vorschau\n\n{self.content.value}",
|
|
view=view,
|
|
ephemeral=True,
|
|
)
|
|
|
|
await view.wait()
|
|
|
|
if view.value:
|
|
await interaction.user.send(f"Confirmed '{self.content.value}'")
|
|
|
|
|
|
@discord.app_commands.command()
|
|
async def post(interaction: discord.Interaction):
|
|
await interaction.response.send_modal(PostModal())
|