Skip to content

CIRCE / DOCUMENTATION

Components

Buttons and select menus routed by customId, by prefix or typed pattern.

Documentation menu
On this page

A file in src/components/ with defineComponent handles buttons and select menus. Two mutually exclusive overloads:

// prefix: longest matching prefix wins
defineComponent({ prefix, execute(ctx), guards?, parse?(customId): Params, metadata? });

// pattern: typed parameters from the customId
defineComponent({ pattern, execute(ctx), guards?, metadata? });

Prefix

export default defineComponent({
  prefix: "btn:ping:",
  async execute({ interaction, t }) {
    await interaction.update({ content: t("ping.reply", { latency: 1 }), components: [] });
  },
});

Pattern

[name] segments become typed params:

export default defineComponent({
  pattern: "ticket:close:[ticketId]:[action]",
  guards: [invokerOnly()],
  async execute({ interaction, params }) {
    // params: { ticketId: string; action: string }
    await interaction.reply(`Ticket ${params.ticketId}: ${params.action}`);
  },
});

Notes

  • prefix and pattern cannot be combined.
  • A customId is limited to 100 characters by Discord.
  • Duplicate or colliding prefixes are a DiscoveryConflictError. Inspect them with circe routes.
  • Fields: component context. For paged embeds: Pagination.