Skip to content
Functioncustom-idv0.2.7

decodeFor

Decode a wire against several customIds at once, for a handler serving more than one.

Matching runs on the prefix. The result pairs the matched prefix with that definition's own params. Switching on prefix narrows both together.

Throws:

  • When no definition owns the wire, or when the matched one refuses it.

decodeFor<Defs>(
    defs: Defs,
    wire: string
): DecodedRoute<Defs>
const Approve = new CustomId('approve').snowflake('userId');
const Reject = new CustomId('reject').snowflake('userId').str('reason');

const { prefix, params } = decodeFor([Approve, Reject], wire);
// params.reason exists on this branch alone
if (prefix === 'reject') await deny(params.userId, params.reason);

Defs

Defs

defs

defs: Defs

The customId definitions to try, in order.

wire

wire: string

The customId string from the interaction.