Text Input
type: 4
Modales
Vista previa modal.json
El Text Input es un campo de texto que el usuario rellena dentro de un modal. Puede ser de una línea o de varias (párrafo). Va siempre dentro de un Label.
Reportar un problema
Título*
Resume el problema
Descripción*
¿Qué pasó? ¿Cómo podemos reproducirlo?
Cuando hago clic en...
Versión
v2.4.1
{ "type": 9, "data": { "custom_id": "reporte", "title": "Reportar un problema", "components": [ { "type": 18, "label": "Título", "component": { "type": 4, "custom_id": "titulo", "style": 1, "placeholder": "Resume el problema", "min_length": 5, "max_length": 80 } }, { "type": 18, "label": "Descripción", "description": "¿Qué pasó? ¿Cómo podemos reproducirlo?", "component": { "type": 4, "custom_id": "descripcion", "style": 2, "placeholder": "Cuando hago clic en...", "max_length": 2000 } }, { "type": 18, "label": "Versión", "component": { "type": 4, "custom_id": "version", "style": 1, "value": "v2.4.1", "required": false } } ] }}| Campo | Tipo | Descripción |
|---|---|---|
type |
entero | obligatorio Siempre 4. |
id |
entero | opcional Identificador único. |
custom_id |
string | obligatorio 1-100 caracteres. |
style |
entero | obligatorio 1 = una línea (Short), 2 = párrafo (Paragraph). |
min_length |
entero | opcional Longitud mínima (0-4000). |
max_length |
entero | opcional Longitud máxima (1-4000). |
required |
booleano | opcional Si es obligatorio. Por defecto true. |
value |
string | opcional Texto ya escrito al abrir. Máx. 4000 caracteres. |
placeholder |
string | opcional Texto de ejemplo en gris. Máx. 100 caracteres. |
label |
string | obsoleto Usa un Label en su lugar. |
Responde a la interacción con el JSON de arriba. Al enviar, recibirás value con el texto escrito.
await interaction.showModal({ custom_id: 'reporte', title: 'Reportar un problema', components: [ { type: 18, label: 'Título', component: { type: 4, custom_id: 'titulo', style: 1, min_length: 5, max_length: 80 } }, { type: 18, label: 'Descripción', component: { type: 4, custom_id: 'descripcion', style: 2, max_length: 2000 } }, ],});
// Al enviar el modalif (interaction.isModalSubmit() && interaction.customId === 'reporte') { const titulo = interaction.fields.getTextInputValue('titulo'); const descripcion = interaction.fields.getTextInputValue('descripcion');}class Reporte(discord.ui.Modal, title="Reportar un problema"): titulo = discord.ui.Label( text="Título", component=discord.ui.TextInput(style=discord.TextStyle.short, min_length=5, max_length=80), ) descripcion = discord.ui.Label( text="Descripción", description="¿Qué pasó? ¿Cómo podemos reproducirlo?", component=discord.ui.TextInput(style=discord.TextStyle.paragraph, max_length=2000), )
async def on_submit(self, interaction: discord.Interaction): await interaction.response.send_message( f"Reporte recibido: **{self.titulo.component.value}**", ephemeral=True )discordgo.Label{ Label: "Descripción", Component: discordgo.TextInput{ CustomID: "descripcion", Style: discordgo.TextInputParagraph, MaxLength: 2000, },}