Skip to content

Commit d6c1a69

Browse files
authored
example update
1 parent 7c5587d commit d6c1a69

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed

examples/modal_dialogs.py

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ def __init__(self, *args, **kwargs) -> None:
2222
label="Longer Input",
2323
value="Longer Value\nSuper Long Value",
2424
style=discord.InputTextStyle.long,
25+
description="You can also describe the purpose of this input."
26+
),
27+
discord.ui.TextDisplay("# Personal Questions"),
28+
discord.ui.Select(
29+
label="What's your favorite color?",
30+
placeholder="Select a color",
31+
options=[
32+
discord.SelectOption(label="Red", emoji="🟥"),
33+
discord.SelectOption(label="Green", emoji="🟩"),
34+
discord.SelectOption(label="Blue", emoji="🟦"),
35+
],
36+
description="If it is not listed, skip this question.",
37+
required=False
2538
),
2639
*args,
2740
**kwargs,
@@ -70,36 +83,36 @@ async def modal_user(ctx: discord.ApplicationContext, member: discord.Member):
7083
async def modaltest(ctx: commands.Context):
7184
"""Shows an example of modals being invoked from an interaction component (e.g. a button or select menu)"""
7285

73-
class MyView(discord.ui.View):
74-
@discord.ui.button(label="Modal Test", style=discord.ButtonStyle.primary)
75-
async def button_callback(
76-
self, button: discord.ui.Button, interaction: discord.Interaction
77-
):
78-
modal = MyModal(title="Modal Triggered from Button")
79-
await interaction.response.send_modal(modal)
80-
81-
@discord.ui.select(
82-
placeholder="Pick Your Modal",
83-
min_values=1,
84-
max_values=1,
85-
options=[
86-
discord.SelectOption(
87-
label="First Modal", description="Shows the first modal"
88-
),
89-
discord.SelectOption(
90-
label="Second Modal", description="Shows the second modal"
91-
),
92-
],
93-
)
94-
async def select_callback(
95-
self, select: discord.ui.Select, interaction: discord.Interaction
96-
):
97-
modal = MyModal(title="Temporary Title")
98-
modal.title = select.values[0]
99-
await interaction.response.send_modal(modal)
100-
101-
view = MyView()
102-
await ctx.send("Click Button, Receive Modal", view=view)
86+
class MyView(discord.ui.View):
87+
@discord.ui.button(label="Modal Test", style=discord.ButtonStyle.primary)
88+
async def button_callback(
89+
self, button: discord.ui.Button, interaction: discord.Interaction
90+
):
91+
modal = MyModal(title="Modal Triggered from Button")
92+
await interaction.response.send_modal(modal)
93+
94+
@discord.ui.select(
95+
placeholder="Pick Your Modal",
96+
min_values=1,
97+
max_values=1,
98+
options=[
99+
discord.SelectOption(
100+
label="First Modal", description="Shows the first modal"
101+
),
102+
discord.SelectOption(
103+
label="Second Modal", description="Shows the second modal"
104+
),
105+
],
106+
)
107+
async def select_callback(
108+
self, select: discord.ui.Select, interaction: discord.Interaction
109+
):
110+
modal = MyModal(title="Temporary Title")
111+
modal.title = select.values[0]
112+
await interaction.response.send_modal(modal)
113+
114+
view = MyView()
115+
await ctx.send("Click Button, Receive Modal", view=view)
103116

104117

105118
bot.run("TOKEN")

0 commit comments

Comments
 (0)