Skip to main content

Class: InteractionOptionResolver

Utility class for resolving command interaction options while working with the raw API. Based on https://github.com/discordjs/discord.js/blob/main/packages/discord.js/src/structures/CommandInteractionOptionResolver.js

Constructors

new InteractionOptionResolver()

new InteractionOptionResolver(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction): InteractionOptionResolver

Parameters

ParameterType
interactionAPIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction

Returns

InteractionOptionResolver

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:61

Properties

data

private readonly data: null | APIApplicationCommandInteractionDataOption[] = null

The interaction options array

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:34


group

private readonly group: null | string = null

The name of the subcommand group

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:54


hoistedOptions

private readonly hoistedOptions: null | APIApplicationCommandInteractionDataOption[] = null

Bottom-level options for the interaction If there is a subcommand (or subcommand and group), this represents the options for the subcommand.

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:49


interaction

private readonly interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:29


resolved

private readonly resolved: null | APIInteractionDataResolved | APIUserInteractionDataResolved | APIMessageApplicationCommandInteractionDataResolved = null

The interaction resolved data

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:39


subcommand

private readonly subcommand: null | string = null

The name of the subcommand

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:59

Methods

get()

get(name, required)

get(name: string, required?: boolean): null | APIApplicationCommandInteractionDataOption

Gets an option by its name

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | APIApplicationCommandInteractionDataOption

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:83

get(name, required)

get(name: string, required: true): APIApplicationCommandInteractionDataOption

Gets an option by its name

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

APIApplicationCommandInteractionDataOption

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:84


getAttachment()

getAttachment(name, required)

getAttachment(name: string, required?: boolean): null | APIAttachment

Gets an attachment option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | APIAttachment

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:238

getAttachment(name, required)

getAttachment(name: string, required: true): APIAttachment

Gets an attachment option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

APIAttachment

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:239


getBoolean()

getBoolean(name, required)

getBoolean(name: string, required?: boolean): null | boolean

Gets a boolean option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | boolean

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:134

getBoolean(name, required)

getBoolean(name: string, required: true): boolean

Gets a boolean option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

boolean

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:135


getChannel()

getChannel(name, required)

getChannel(name: string, required?: boolean): null | APIInteractionDataResolvedChannel

Gets a channel option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | APIInteractionDataResolvedChannel

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:147

getChannel(name, required)

getChannel(name: string, required: true): APIInteractionDataResolvedChannel

Gets a channel option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

APIInteractionDataResolvedChannel

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:148


getFocusedOption()

getFocusedOption(): object | object | object

Gets the focused option for an autocomplete interaction

Returns

object | object | object

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:327


getInteger()

getInteger(name, required)

getInteger(name: string, required?: boolean): null | number

Gets an integer option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | number

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:173

getInteger(name, required)

getInteger(name: string, required: true): number

Gets an integer option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

number

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:174


getMember()

getMember(name, required)

getMember(name: string, required?: boolean): null | APIInteractionDataResolvedGuildMember

Gets a member option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | APIInteractionDataResolvedGuildMember

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:212

getMember(name, required)

getMember(name: string, required: true): APIInteractionDataResolvedGuildMember

Gets a member option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

APIInteractionDataResolvedGuildMember

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:213


getMentionable()

getMentionable(name, required)

getMentionable(name: string, required?: boolean): null | APIRole | APIUser | APIInteractionDataResolvedGuildMember

Gets a mentionable option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | APIRole | APIUser | APIInteractionDataResolvedGuildMember

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:251

getMentionable(name, required)

getMentionable(name: string, required: true): APIRole | APIUser | APIInteractionDataResolvedGuildMember

Gets a mentionable option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

APIRole | APIUser | APIInteractionDataResolvedGuildMember

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:252


getNumber()

getNumber(name, required)

getNumber(name: string, required?: boolean): null | number

Gets a number option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | number

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:186

getNumber(name, required)

getNumber(name: string, required: true): number

Gets a number option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

number

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:187


getRole()

getRole(name, required)

getRole(name: string, required?: boolean): null | APIRole

Gets a role option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | APIRole

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:225

getRole(name, required)

getRole(name: string, required: true): APIRole

Gets a role option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

APIRole

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:226


getString()

getString(name, required)

getString(name: string, required?: boolean): null | string

Gets a string option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | string

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:160

getString(name, required)

getString(name: string, required: true): string

Gets a string option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

string

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:161


getSubcommand()

getSubcommand(required)

getSubcommand(required?: boolean): null | string

Gets the selected subcommand

Parameters
ParameterTypeDescription
required?booleanWhether to throw an error if there is no subcommand
Returns

null | string

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:104

getSubcommand(required)

getSubcommand(required: true): string

Gets the selected subcommand

Parameters
ParameterTypeDescription
requiredtrueWhether to throw an error if there is no subcommand
Returns

string

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:105


getSubcommandGroup()

getSubcommandGroup(required)

getSubcommandGroup(required?: boolean): null | string

Gets the selected subcommand group

Parameters
ParameterTypeDescription
required?booleanWhether to throw an error if there is no subcommand group
Returns

null | string

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:119

getSubcommandGroup(required)

getSubcommandGroup(required: true): string

Gets the selected subcommand group

Parameters
ParameterTypeDescription
requiredtrueWhether to throw an error if there is no subcommand group
Returns

string

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:120


getTargetMember()

getTargetMember(required)

getTargetMember(required?: boolean): null | APIInteractionDataResolvedGuildMember

Gets the target member for a context menu interaction

Parameters
ParameterTypeDescription
required?booleanWhether to throw an error if the member data is not present
Returns

null | APIInteractionDataResolvedGuildMember

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:292

getTargetMember(required)

getTargetMember(required: true): APIInteractionDataResolvedGuildMember

Gets the target member for a context menu interaction

Parameters
ParameterTypeDescription
requiredtrueWhether to throw an error if the member data is not present
Returns

APIInteractionDataResolvedGuildMember

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:293


getTargetMessage()

getTargetMessage(): APIMessage

Gets the target message for a context menu interaction

Returns

APIMessage

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:316


getTargetUser()

getTargetUser(): APIUser

Gets the target user for a context menu interaction

Returns

APIUser

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:284


getTypedOption()

getTypedOption(name, type, required)

private getTypedOption<Option>(name: string, type: Option, required?: boolean): null | TypeToOptionMap[Option]

Type parameters
Type parameter
Option extends String | Integer | Boolean | User | Channel | Role | Mentionable | Number | Attachment
Parameters
ParameterType
namestring
typeOption
required?boolean
Returns

null | TypeToOptionMap[Option]

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:348

getTypedOption(name, type, required)

private getTypedOption<Option>(name: string, type: Option, required: true): TypeToOptionMap[Option]

Type parameters
Type parameter
Option extends String | Integer | Boolean | User | Channel | Role | Mentionable | Number | Attachment
Parameters
ParameterType
namestring
typeOption
requiredtrue
Returns

TypeToOptionMap[Option]

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:354


getUser()

getUser(name, required)

getUser(name: string, required?: boolean): null | APIUser

Gets a user option

Parameters
ParameterTypeDescription
namestringThe name of the option
required?booleanWhether to throw an error if the option is not found
Returns

null | APIUser

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:199

getUser(name, required)

getUser(name: string, required: true): APIUser

Gets a user option

Parameters
ParameterTypeDescription
namestringThe name of the option
requiredtrueWhether to throw an error if the option is not found
Returns

APIUser

Source

projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:200