Skip to content

Commit 3cc921b

Browse files
committed
docs: update modal guide
1 parent c453b2a commit 3cc921b

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

docs/src/Guides/06 Modals.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ You **cannot** respond to a modal with a modal.
1818
Use `ctx.send_modal()` to send a modal.
1919

2020
```python
21+
from interactions import slash_command, SlashContext, Modal, ShortText, ParagraphText
22+
2123
@slash_command(name="my_modal_command", description="Playing with Modals")
22-
async def my_command_function(ctx: InteractionContext):
24+
async def my_command_function(ctx: SlashContext):
2325
my_modal = Modal(
26+
ShortText(label="Short Input Text", custom_id="short_text"),
27+
ParagraphText(label="Long Input Text", custom_id="long_text"),
2428
title="My Modal",
25-
components=[
26-
ShortText(label="Short Input Text", custom_id="short_text"),
27-
ParagraphText(label="Long Input Text", custom_id="long_text"),
28-
],
2929
)
3030
await ctx.send_modal(modal=my_modal)
3131
...
@@ -43,6 +43,8 @@ As with `bot.wait_for_component()`, `bot.wait_for_modal()` supports timeouts. Ch
4343

4444
```python
4545
...
46+
from interactions import ModalContext
47+
4648
modal_ctx: ModalContext = await ctx.bot.wait_for_modal(my_modal)
4749
await modal_ctx.send(f"""You input {modal_ctx.responses["short_text"]} and {modal_ctx.responses["long_text"]}""")
4850
```
@@ -57,12 +59,13 @@ As previously mentioned, you really want to set your own `custom_id` otherwise y
5759
Modal components are customisable in their appearance. You can set a placeholder, pre-fill them, restrict what users can input, or make them optional.
5860

5961
```python
62+
from interactions import slash_command, Modal, ShortText, SlashContext
63+
64+
6065
@slash_command(name="my_modal_command", description="Playing with Modals")
61-
async def my_command_function(ctx: InteractionContext):
62-
my_modal = Modal(
63-
title="My Modal",
64-
components=[
65-
ShortText(
66+
async def my_command_function(ctx: SlashContext):
67+
my_modal = Modal(
68+
ShortText(
6669
label="Short Input Text",
6770
custom_id="short_text",
6871
value="Pre-filled text",
@@ -75,10 +78,12 @@ async def my_command_function(ctx: InteractionContext):
7578
placeholder="Please be concise",
7679
max_length=10,
7780
),
78-
],
81+
title="My Modal",
7982
)
83+
84+
8085
await ctx.send_modal(modal=my_modal)
81-
...
86+
...
8287
```
8388

8489
This example leads to the following modal:

0 commit comments

Comments
 (0)