Radio Group, Checkbox Group and Checkbox
type: 21 · 22 · 23
Modals
Preview modal.json
Three components that let the user choose inside a modal, all inside a Label:
| Type | Name | For |
|---|---|---|
21 |
Radio Group | Pick one option out of 2 to 10. |
22 |
Checkbox Group | Pick several options out of 1 to 10. |
23 |
Checkbox | A single yes / no box. |
Quick survey
How often do you play?*
Every day
Weekends
Now and then
Once a month or less
What are you interested in?*
Tournaments
Giveaways
Voice events
Send me notifications by DM
{ "type": 9, "data": { "custom_id": "survey", "title": "Quick survey", "components": [ { "type": 18, "label": "How often do you play?", "component": { "type": 21, "custom_id": "frequency", "options": [ { "label": "Every day", "value": "daily", "default": true }, { "label": "Weekends", "value": "weekends" }, { "label": "Now and then", "value": "sometimes", "description": "Once a month or less" } ] } }, { "type": 18, "label": "What are you interested in?", "component": { "type": 22, "custom_id": "interests", "min_values": 0, "options": [ { "label": "Tournaments", "value": "tournaments" }, { "label": "Giveaways", "value": "giveaways", "default": true }, { "label": "Voice events", "value": "voice" } ] } }, { "type": 18, "label": "Send me notifications by DM", "component": { "type": 23, "custom_id": "dm_notifications" } } ] }}Radio Group (21)
Section titled “Radio Group (21)”| Field | Type | Description |
|---|---|---|
type |
integer | required Always 21. |
custom_id |
string | required 1-100 characters. |
options |
array of options | required 2 to 10 options. |
required |
boolean | optional Defaults to true. |
You receive: value (string with the picked value, or null if nothing was picked).
Checkbox Group (22)
Section titled “Checkbox Group (22)”| Field | Type | Description |
|---|---|---|
type |
integer | required Always 22. |
custom_id |
string | required 1-100 characters. |
options |
array of options | required 1 to 10 options. |
min_values |
integer | optional 0-10. Defaults to 1. Must be at least 1 if required is true. |
max_values |
integer | optional 1-10. Defaults to the number of options. |
required |
boolean | optional Defaults to true. |
You receive: values (array of strings; [] if nothing was picked).
Checkbox (23)
Section titled “Checkbox (23)”| Field | Type | Description |
|---|---|---|
type |
integer | required Always 23. |
custom_id |
string | required 1-100 characters. |
default |
boolean | optional Whether it starts checked. |
You receive: value (true if checked, false if not).
Option
Section titled “Option”| Field | Type | Description |
|---|---|---|
value |
string | required Max 100 characters. |
label |
string | required Max 100 characters. |
description |
string | optional Max 100 characters. |
default |
boolean | optional Whether it starts selected. |
Respond to the interaction with the JSON above ("type": 9).
await interaction.showModal({ custom_id: 'survey', title: 'Quick survey', components: [ { type: 18, label: 'How often do you play?', component: { type: 21, custom_id: 'frequency', options: [ { label: 'Every day', value: 'daily' }, { label: 'Weekends', value: 'weekends' }, ], }, }, { type: 18, label: 'Send me notifications by DM', component: { type: 23, custom_id: 'dm_notifications' } }, ],});
// On submit (recent discord.js versions)if (interaction.isModalSubmit() && interaction.customId === 'survey') { const frequency = interaction.fields.getRadioGroup('frequency'); // string or null const dms = interaction.fields.getCheckbox('dm_notifications'); // true / false}class Survey(discord.ui.Modal, title="Quick survey"): frequency = discord.ui.Label(text="How often do you play?", component=discord.ui.RadioGroup()) interests = discord.ui.Label(text="What are you interested in?", component=discord.ui.CheckboxGroup(min_values=0)) dms = discord.ui.Label(text="Send me notifications by DM", component=discord.ui.Checkbox())
def __init__(self): super().__init__() self.frequency.component.add_option(label="Every day", value="daily") self.frequency.component.add_option(label="Weekends", value="weekends") self.interests.component.add_option(label="Tournaments", value="tournaments") self.interests.component.add_option(label="Giveaways", value="giveaways")
async def on_submit(self, interaction: discord.Interaction): frequency = self.frequency.component.value # str or None interests = self.interests.component.values # list[str] dms = self.dms.component.value # bool await interaction.response.send_message("Thanks for answering!", ephemeral=True)Requires a discord.py version that includes RadioGroup, CheckboxGroup and Checkbox (main branch / most recent releases).
discordgo doesn’t have types for these components yet. You can send the modal with your own HTTP request using the JSON above:
body := map[string]any{ "type": 9, "data": map[string]any{ "custom_id": "survey", "title": "Quick survey", "components": []any{ map[string]any{ "type": 18, "label": "Send me notifications by DM", "component": map[string]any{"type": 23, "custom_id": "dm_notifications"}, }, }, },}
endpoint := discordgo.EndpointInteractionResponse(i.ID, i.Token)_, err := s.RequestWithBucketID("POST", endpoint, body, endpoint)