Example code for handling a modal submission. Triggers when a user submits a modal with a custom id of "feedback-modal", and displays what the user wrote in the modal as an ephemeral message. Intended to be used with the slash command in this snippet: https://autocode.com/snippet/jacoblee/cachsnpt_daT6NWdSv6ibwAq2ti9jCbUY5vrA73gFk2xA/
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let messageLines = [
`Hey <@!${context.params.event.member.user.id}>! Here's what you answered with:`,
``,
];
messageLines = messageLines.concat(
context.params.event.data.components.map((componentRow) => {
let textField = componentRow.components[0];
return [`**${textField.custom_id}:**`, ``, textField.value, ''].join('\n');
})
);
await lib.discord.interactions['@1.0.0'].responses.ephemeral.create({
token: `${context.params.event.token}`,
content: messageLines.join('\n'),
response_type: 'CHANNEL_MESSAGE_WITH_SOURCE',
});