Options
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.
| Helper | Getter | Returns |
|---|---|---|
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 details = .('details');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 days = .('days');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 member = .('target');Channels
channel_types narrows the channel the getter returns:
const = ({
: 'log',
: 'Set the log channel',
: {
: ({
: 'Where',
: true,
: [.],
}),
},
});
const = (, );
const target = .('target');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');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.
