Skip to content

snap()

Popii


Popii / 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.

T extends PopiiComponentDefinition<any, any, PopiiLocals & Record<string, any>>

T

T

src/snaps/confirm.ts
import { snap } from "popii";
export default snap({
customId: "confirm",
async do(pop) {
await pop.reply({ content: "Confirmed!", ephemeral: true });
}
});
src/snaps/delete.ts
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 });
}
});
src/snaps/vote.ts
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 });
}
});