Class: InteractionOptionResolver
@sapphire/discord-utilities.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
constructor
• new InteractionOptionResolver(interaction
)
Parameters
Name | Type |
---|---|
interaction | APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction |
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:61
Properties
data
• Private
Readonly
data: null
| APIApplicationCommandInteractionDataOption
[] = null
The interaction options array
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:34
group
• Private
Readonly
group: null
| string
= null
The name of the subcommand group
Defined in
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.
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:49
interaction
• Private
Readonly
interaction: APIApplicationCommandInteraction
| APIApplicationCommandAutocompleteInteraction
| APIModalSubmitInteraction
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:29
resolved
• Private
Readonly
resolved: null
| APIInteractionDataResolved
| APIUserInteractionDataResolved
| APIMessageApplicationCommandInteractionDataResolved
= null
The interaction resolved data
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:39
subcommand
• Private
Readonly
subcommand: null
| string
= null
The name of the subcommand
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:59
Methods
get
▸ get(name
, required?
): null
| APIApplicationCommandInteractionDataOption
Gets an option by its name
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| APIApplicationCommandInteractionDataOption
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:83
▸ get(name
, required
): APIApplicationCommandInteractionDataOption
Gets an option by its name
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
APIApplicationCommandInteractionDataOption
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:84
getAttachment
▸ getAttachment(name
, required?
): null
| APIAttachment
Gets an attachment option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| APIAttachment
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:238
▸ getAttachment(name
, required
): APIAttachment
Gets an attachment option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
APIAttachment
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:239
getBoolean
▸ getBoolean(name
, required?
): null
| boolean
Gets a boolean option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| boolean
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:134
▸ getBoolean(name
, required
): boolean
Gets a boolean option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
boolean
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:135
getChannel
▸ getChannel(name
, required?
): null
| APIInteractionDataResolvedChannel
Gets a channel option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| APIInteractionDataResolvedChannel
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:147
▸ getChannel(name
, required
): APIInteractionDataResolvedChannel
Gets a channel option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
APIInteractionDataResolvedChannel
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:148
getFocusedOption
▸ getFocusedOption(): { name
: string
; type
: Integer
; value
: number
} | { name
: string
; type
: Number
; value
: number
} | { name
: string
; type
: String
; value
: string
}
Gets the focused option for an autocomplete interaction
Returns
{ name
: string
; type
: Integer
; value
: number
} | { name
: string
; type
: Number
; value
: number
} | { name
: string
; type
: String
; value
: string
}
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:327
getInteger
▸ getInteger(name
, required?
): null
| number
Gets an integer option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| number
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:173
▸ getInteger(name
, required
): number
Gets an integer option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
number
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:174
getMember
▸ getMember(name
, required?
): null
| APIInteractionDataResolvedGuildMember
Gets a member option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| APIInteractionDataResolvedGuildMember
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:212
▸ getMember(name
, required
): APIInteractionDataResolvedGuildMember
Gets a member option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
APIInteractionDataResolvedGuildMember
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:213
getMentionable
▸ getMentionable(name
, required?
): null
| APIRole
| APIUser
| APIInteractionDataResolvedGuildMember
Gets a mentionable option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| APIRole
| APIUser
| APIInteractionDataResolvedGuildMember
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:251
▸ getMentionable(name
, required
): APIRole
| APIUser
| APIInteractionDataResolvedGuildMember
Gets a mentionable option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
APIRole
| APIUser
| APIInteractionDataResolvedGuildMember
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:252
getNumber
▸ getNumber(name
, required?
): null
| number
Gets a number option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| number
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:186
▸ getNumber(name
, required
): number
Gets a number option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
number
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:187
getRole
▸ getRole(name
, required?
): null
| APIRole
Gets a role option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| APIRole
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:225
▸ getRole(name
, required
): APIRole
Gets a role option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
APIRole
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:226
getString
▸ getString(name
, required?
): null
| string
Gets a string option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| string
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:160
▸ getString(name
, required
): string
Gets a string option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
string
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:161
getSubcommand
▸ getSubcommand(required?
): null
| string
Gets the selected subcommand
Parameters
Name | Type | Description |
---|---|---|
required? | boolean | Whether to throw an error if there is no subcommand |
Returns
null
| string
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:104
▸ getSubcommand(required
): string
Gets the selected subcommand
Parameters
Name | Type | Description |
---|---|---|
required | true | Whether to throw an error if there is no subcommand |
Returns
string
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:105
getSubcommandGroup
▸ getSubcommandGroup(required?
): null
| string
Gets the selected subcommand group
Parameters
Name | Type | Description |
---|---|---|
required? | boolean | Whether to throw an error if there is no subcommand group |
Returns
null
| string
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:119
▸ getSubcommandGroup(required
): string
Gets the selected subcommand group
Parameters
Name | Type | Description |
---|---|---|
required | true | Whether to throw an error if there is no subcommand group |
Returns
string
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:120
getTargetMember
▸ getTargetMember(required?
): null
| APIInteractionDataResolvedGuildMember
Gets the target member for a context menu interaction
Parameters
Name | Type | Description |
---|---|---|
required? | boolean | Whether to throw an error if the member data is not present |
Returns
null
| APIInteractionDataResolvedGuildMember
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:292
▸ getTargetMember(required
): APIInteractionDataResolvedGuildMember
Gets the target member for a context menu interaction
Parameters
Name | Type | Description |
---|---|---|
required | true | Whether to throw an error if the member data is not present |
Returns
APIInteractionDataResolvedGuildMember
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:293
getTargetMessage
▸ getTargetMessage(): APIMessage
Gets the target message for a context menu interaction
Returns
APIMessage
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:316
getTargetUser
▸ getTargetUser(): APIUser
Gets the target user for a context menu interaction
Returns
APIUser
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:284
getTypedOption
▸ Private
getTypedOption<Option
>(name
, type
, required?
): null
| TypeToOptionMap
[Option
]
Type parameters
Name | Type |
---|---|
Option | extends String | Integer | Boolean | User | Channel | Role | Mentionable | Number | Attachment |
Parameters
Name | Type |
---|---|
name | string |
type | Option |
required? | boolean |
Returns
null
| TypeToOptionMap
[Option
]
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:348
▸ Private
getTypedOption<Option
>(name
, type
, required
): TypeToOptionMap
[Option
]
Type parameters
Name | Type |
---|---|
Option | extends String | Integer | Boolean | User | Channel | Role | Mentionable | Number | Attachment |
Parameters
Name | Type |
---|---|
name | string |
type | Option |
required | true |
Returns
TypeToOptionMap
[Option
]
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:354
getUser
▸ getUser(name
, required?
): null
| APIUser
Gets a user option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required? | boolean | Whether to throw an error if the option is not found |
Returns
null
| APIUser
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:199
▸ getUser(name
, required
): APIUser
Gets a user option
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the option |
required | true | Whether to throw an error if the option is not found |
Returns
APIUser
Defined in
projects/utilities/packages/discord-utilities/src/lib/InteractionOptionResolver.ts:200