snap()
Popii / snap
Function: snap()
Section titled “Function: snap()”snap<
T>(definition):T
Defined in: define/snap.ts:55
Defines a persistent handler for Buttons, Select Menus, and Modals.
Snaps match incoming interactions by customId (exact string or RegExp).
Unlike one-shot collectors, Snaps survive bot restarts because they are
registered by pattern at startup, not per-message.
Drop the file in src/snaps/ and Popii registers it automatically.
Type Parameters
Section titled “Type Parameters”T extends PopiiComponentDefinition<any, any, PopiiLocals & Record<string, any>>
Parameters
Section titled “Parameters”definition
Section titled “definition”T
Returns
Section titled “Returns”T
Examples
Section titled “Examples”import { snap } from "popii";
export default snap({ customId: "confirm", async do(pop) { await pop.reply({ content: "Confirmed!", ephemeral: true }); }});import { snap } from "popii";
export default snap({ customId: /^delete:(\d+)$/, async do(pop) { const messageId = pop.snapMatches?.[1]; await pop.reply({ content: `Deleted message ${messageId}`, ephemeral: true }); }});import { snap } from "popii";
export default snap({ prefix: "vote", async do(pop) { const { pollId, choice } = pop.snapData; // decoded from pack() await pop.reply({ content: `Voted ${choice} on poll ${pollId}`, ephemeral: true }); }});