Skip to Content
nyx logonyx guide

Options

Reading time:4 min read

Each option is defined with a helper, under the name it will have in Discord. The helpers take the same fields as the API (description, required, choices, min_value...), and typedOptions() gives you one getter per option kind.

HelperGetterReturns
string()getString()string
integer()getInteger()number
number()getNumber()number
boolean()getBoolean()boolean
user()getUser(), getMember()The user, and the member
channel()getChannel()The channel
role()getRole()The role
mentionable()getMentionable()A user, member or role
attachment()getAttachment()The attachment

Every getter only accepts the names of options of its own kind. What it returns is the same as in your library, so getUser() returns a User on discord.js and an APIUser with raw payloads.

Required options

A getter returns null unless the option is required: true, in which case Discord always sends it and the type is not nullable:

const  = ({
  : 'report',
  : 'Report something',
  : {
    : ({ : 'Title', : true }),
    : ({ : 'Details' }),
  },
});

const  = (, );

const title = .('title');
const title: string
const details = .('details');
const details: string | null

Choices

When an option has choices, the getter returns the union of their values:

const  = ({
  : 'ban',
  : 'Ban a member',
  : {
    : ({
      : 'How',
      : true,
      : [
        { : 'Soft', : 'soft' },
        { : 'Hard', : 'hard' },
      ],
    }),
    : ({
      : 'Days of messages to delete',
      : [
        { : 'None', : 0 },
        { : 'Week', : 7 },
      ],
    }),
  },
});

const  = (, );

const mode = .('mode');
const mode: "hard" | "soft"
const days = .('days');
const days: 0 | 7 | null

Users and members

A user() option resolves to a user, but the user might not be in the guild (or the command might run in a DM), so getMember() is always nullable, even for required options:

const  = ({
  : 'kick',
  : 'Kick a member',
  : {
    : ({ : 'Who', : true }),
  },
});

const  = (, );

const target = .('target');
const target: User
const member = .('target');
const member: APIInteractionDataResolvedGuildMember | GuildMember | null

Channels

channel_types narrows the channel the getter returns:

const  = ({
  : 'log',
  : 'Set the log channel',
  : {
    : ({
      : 'Where',
      : true,
      : [.],
    }),
  },
});

const  = (, );

const target = .('target');
const target: (APIInteractionDataResolvedChannelBase<ChannelType.GuildText | ChannelType.DM | ChannelType.GuildVoice | ChannelType.GroupDM | ChannelType.GuildCategory | ChannelType.GuildAnnouncement | ChannelType.GuildStageVoice | ChannelType.GuildDirectory | ChannelType.GuildForum | ChannelType.GuildMedia> & {
    readonly type: ChannelType.GuildText;
}) | (TextChannel & {
    readonly type: ChannelType.GuildText;
})

Mentionables

getMentionable() returns the union of what a mentionable can be: a user, a member or a role. Use getMember() and getRole() for the other kinds' own options.

Raw payloads

With @nyx-discord/typed-options/djs-core there is no library to resolve the options for you, so typedOptions() reads them from the payload and looks up the users, members, channels, roles and attachments in resolved by their ID. Options missing from the payload are null:

const  = ({
  : 'kick',
  : 'Kick a member',
  : {
    : ({ : 'Who', : true }),
  },
});

const  = (, );

const target = .('target');
const target: APIUser

It takes the interaction payload itself, or the @discordjs/core event props that wrap it as data, so it works the same for the gateway, for HTTP bots and for any other library.

On this page