📝 Modal
Como obter: `Modal()`
Métodos
| Assinatura | Parâmetro(s) | Descrição |
|---|---|---|
| setTitle(v) | string | Form title (max. 45 characters) |
| addTextInput(customId, label, opts?) | string, string, object? | Adds a text field. opts: { style: "short"|"long", placeholder, required, minLength, maxLength, value } |
| onSubmit(fn, opts?) | function, object? | Registers the form submission. fn(interaction, fields) — fields holds each field's value by customId. opts: { user: true|"id", ttl: ms } |
On the interaction object
| Assinatura | Parâmetro(s) | Descrição |
|---|---|---|
| interaction.showModal(modal) | Modal | Opens the form. modal must have already gone through .onSubmit(fn) |
Discord limitation: a Modal only opens in response to an existing interaction (inside
on(buttonClick) or on(selectMenu), or in the temporary .onClick() of a Button/SelectMenu) — never from on(command), which is a plain message with no interaction token behind it.Exemplo de uso
on command("feedback", message, args)
let btn = Button()
.setLabel("Dar feedback")
.onClick(function(interaction)
let modal = Modal()
.setTitle("Feedback")
.addTextInput("nota", "Nota de 1 a 5", { style: "short" })
.addTextInput("comentario", "Comentário", { style: "long", required: false })
.onSubmit(function(interaction, fields)
interaction.reply("Recebido! Nota: " .. fields.nota .. " — " .. fields.comentario)
end)
interaction.showModal(modal)
end)
message.reply("Clica pra dar feedback:", { components: [btn] })
end