Skip to content

Commit a846b43

Browse files
authored
update examples
1 parent 20aae0f commit a846b43

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

examples/modal_dialogs.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,41 @@
1111
)
1212

1313

14-
class MyModal(discord.ui.Modal):
14+
class MyModal(discord.ui.DesignerModal):
1515
def __init__(self, *args, **kwargs) -> None:
16-
super().__init__(
16+
first_input = discord.ui.Label(
1717
discord.ui.InputText(
18-
label="Short Input",
1918
placeholder="Placeholder Test",
2019
),
20+
label="Short Input"
21+
)
22+
second_input = discord.ui.Label(
2123
discord.ui.InputText(
22-
label="Longer Input",
24+
placeholder="Placeholder Test",
2325
value="Longer Value\nSuper Long Value",
2426
style=discord.InputTextStyle.long,
25-
description="You can also describe the purpose of this input.",
2627
),
27-
discord.ui.TextDisplay("# Personal Questions"),
28+
label="Longer Input",
29+
description="You can also describe the purpose of this input.",
30+
)
31+
select = discord.ui.Label(
2832
discord.ui.Select(
29-
label="What's your favorite color?",
3033
placeholder="Select a color",
3134
options=[
3235
discord.SelectOption(label="Red", emoji="🟥"),
3336
discord.SelectOption(label="Green", emoji="🟩"),
3437
discord.SelectOption(label="Blue", emoji="🟦"),
3538
],
36-
description="If it is not listed, skip this question.",
3739
required=False,
3840
),
41+
label="What's your favorite color?",
42+
description="If it is not listed, skip this question.",
43+
)
44+
super().__init__(
45+
first_input,
46+
second_input,
47+
discord.ui.TextDisplay("# Personal Questions"), # TextDisplay does NOT use Label
48+
select,
3949
*args,
4050
**kwargs,
4151
)
@@ -45,10 +55,10 @@ async def callback(self, interaction: discord.Interaction):
4555
title="Your Modal Results",
4656
fields=[
4757
discord.EmbedField(
48-
name="First Input", value=self.children[0].value, inline=False
58+
name="First Input", value=self.children[0].item.value, inline=False
4959
),
5060
discord.EmbedField(
51-
name="Second Input", value=self.children[1].value, inline=False
61+
name="Second Input", value=self.children[1].item.value, inline=False
5262
),
5363
],
5464
color=discord.Color.random(),

examples/views/new_components.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@
1919
Separator,
2020
TextDisplay,
2121
Thumbnail,
22-
View,
22+
DesignerView,
23+
ActionRow,
2324
button,
2425
)
2526

27+
class MyRow(ActionRow):
2628

27-
class MyView(View):
29+
@button(label="Delete Message", style=ButtonStyle.red, id=200)
30+
async def delete_button(self, button: Button, interaction: Interaction):
31+
await interaction.response.defer(invisible=True)
32+
await interaction.message.delete()
33+
34+
class MyView(DesignerView):
2835
def __init__(self, user: User):
2936
super().__init__(timeout=30)
3037
text1 = TextDisplay("### This is a sample `TextDisplay` in a `Section`.")
@@ -55,11 +62,8 @@ def __init__(self, user: User):
5562
self.add_item(
5663
TextDisplay("Above is a `MediaGallery` containing two `MediaGalleryItem`s.")
5764
)
58-
59-
@button(label="Delete Message", style=ButtonStyle.red, id=200)
60-
async def delete_button(self, button: Button, interaction: Interaction):
61-
await interaction.response.defer(invisible=True)
62-
await interaction.message.delete()
65+
row = MyRow()
66+
self.add_item(row)
6367

6468
async def on_timeout(self):
6569
self.get_item(200).disabled = True

0 commit comments

Comments
 (0)