Modal
Sends a message with a button that opens up a modal. The modal contains text inputs and a file upload.

modal.sc
__config() -> {
'scope' -> 'global',
'bot' -> 'mybot'
};
global_channel = dc_channel_from_id('put channel id here!');
send_modal(int) -> (
dc_respond_interaction(int, 'respond_modal', {
'id' -> 'example_modal',
'title' -> 'Selection modal',
'components' -> [
{
'component'->'label',
'label' -> 'Your name',
'description' -> 'What\'s your name?',
'child'-> {
'component' -> 'text_input',
'id' -> 'name_input',
'style' -> 'short',
'min_length' -> 2,
'max_length' -> 32,
'required' -> true,
'placeholder' -> 'Put your name here'
},
},
{
'component'->'label',
'label' -> 'Introduce yourself',
'description' -> 'Write a short introduction about your hobbies, things you like or things you don\t like.',
'child'-> {
'component' -> 'text_input',
'id' -> 'introduction_input',
'style' -> 'paragraph',
'required' -> false,
'value' -> 'Hello, I am'
}
},
{
'component'->'label',
'label' -> 'Favorite meme',
'description' -> 'Upload your favorite meme here',
'child'-> {
'component' -> 'file_upload',
'id' -> 'meme_upload',
}
},
]
});
);
task(_() -> (
dc_send_message(global_channel, {
'content' -> 'Click below to open modal',
'components' -> [
[{
'id' -> 'modal_btn',
'component' -> 'button',
'label' -> 'Open modal'
}]
]
});
));
__on_discord_button(int) -> (
if (int~'custom_id' == 'modal_btn',
task(_(outer(int)) -> (
send_modal(int);
));
);
);
__on_discord_modal(interaction) -> (
if(interaction~'custom_id' == 'example_modal',
options = interaction~'values_by_id';
meme = options:'meme_upload'~'value':0;
if(!meme~'is_image',
dc_respond_interaction(interaction, 'respond_immediately', {
'content' -> 'Please upload an image',
});
return();
);
dc_respond_interaction(interaction, 'respond_immediately', {
'use_components_v2' -> true,
'components' -> [
{
'component' -> 'text_display',
'content' -> str(
'# Hello %s.\nThis is your image:',
options:'name_input'~'value',
),
},
{
'component' -> 'media_gallery',
'items' -> [
{
'media' -> {
'url' -> meme~'url',
},
},
],
},
],
});
);
);