Skip to content
Functioncustom-idv0.3.2

decodeFor

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

It decodes with the first definition whose prefix matches the wire. Switching on prefix narrows params to that definition's fields.

Throws:

  • The invalid error from setCustomIdErrors when the wire's prefix doesn't match any definition.

  • What decode throws when the matched definition rejects the wire.

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 only exists on this branch
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.