Exemplos de Uso
Action Row com Botões
Exemplo de como organizar botões dentro de uma Action Row:
const button1 = new Button("Confirmar", 1, "confirm_id");
const button2 = new Button({ label: "Cancelar", style: 2, custom_id: "cancel_id" });
const button3 = new Button()
.setLabel("Ajuda")
.setStyle(3)
.setCustomId("help_id");
const firstActionRow = new ActionRow(button1);
const secondActionRow = new ActionRow().addComponents(button2, button3);
console.log(actionRow.components); // Exibe os botões configurados
Criação de Botões
Os botões podem ser criados de várias formas:
1. Por String
const button = new Button("Clique Aqui", 1, "button_id");
2. Por Objeto
const button = new Button({
label: "Mais Informações",
style: 5,
url: "https://example.com"
});
3. Por Desestruturação
const button = new Button()
.setLabel("Enviar")
.setStyle(1)
.setCustomId("send_id")
.setEmoji("✅");
Evento onClick
Os botões suportam eventos de clique personalizados:
const button = new Button("Confirmação", 1, "confirm_id");
// Configurando o evento onClick
button.onClick(interaction, async (res) => {
await res.reply({ content: "Botão clicado!" });
}, 30000, 1);
Trabalhando com ActionRow
A classe ActionRow
organiza múltiplos componentes, como botões ou menus de seleção, em uma única linha interativa.
const button1 = new Button("Aprovar", 1, "approve_id");
const button2 = new Button("Rejeitar", 4, "reject_id");
const actionRow = new ActionRow(button1, button2);
console.log(actionRow.toJSON());