@sapphire/discord-utilities 3.4.1 → 3.4.2-next.09afdaab
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +0 -67
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +83 -28
- package/dist/esm/index.d.mts +83 -28
- package/dist/esm/index.mjs +0 -67
- package/dist/esm/index.mjs.map +1 -1
- package/dist/iife/index.global.js +56 -70
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +10 -10
package/dist/cjs/index.d.cts
CHANGED
|
@@ -28,38 +28,91 @@ declare class InteractionOptionResolver {
|
|
|
28
28
|
*/
|
|
29
29
|
private readonly subcommand;
|
|
30
30
|
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Gets an option by its name
|
|
33
|
+
* @param name The name of the option
|
|
34
|
+
* @param required Whether to throw an error if the option is not found
|
|
35
|
+
*/
|
|
36
|
+
get<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIApplicationCommandInteractionDataOption>;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the selected subcommand
|
|
39
|
+
* @param required Whether to throw an error if there is no subcommand
|
|
40
|
+
*/
|
|
41
|
+
getSubcommand<Required extends boolean = false>(required?: Required): RequiredIf<Required, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the selected subcommand group
|
|
44
|
+
* @param required Whether to throw an error if there is no subcommand group
|
|
45
|
+
*/
|
|
46
|
+
getSubcommandGroup<Required extends boolean = false>(required?: Required): RequiredIf<Required, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets a boolean option
|
|
49
|
+
* @param name The name of the option
|
|
50
|
+
* @param required Whether to throw an error if the option is not found
|
|
51
|
+
*/
|
|
52
|
+
getBoolean<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Gets a channel option
|
|
55
|
+
* @param name The name of the option
|
|
56
|
+
* @param required Whether to throw an error if the option is not found
|
|
57
|
+
*/
|
|
58
|
+
getChannel<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIInteractionDataResolvedChannel>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets a string option
|
|
61
|
+
* @param name The name of the option
|
|
62
|
+
* @param required Whether to throw an error if the option is not found
|
|
63
|
+
*/
|
|
64
|
+
getString<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets an integer option
|
|
67
|
+
* @param name The name of the option
|
|
68
|
+
* @param required Whether to throw an error if the option is not found
|
|
69
|
+
*/
|
|
70
|
+
getInteger<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, number>;
|
|
71
|
+
/**
|
|
72
|
+
* Gets a number option
|
|
73
|
+
* @param name The name of the option
|
|
74
|
+
* @param required Whether to throw an error if the option is not found
|
|
75
|
+
*/
|
|
76
|
+
getNumber<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, number>;
|
|
77
|
+
/**
|
|
78
|
+
* Gets a user option
|
|
79
|
+
* @param name The name of the option
|
|
80
|
+
* @param required Whether to throw an error if the option is not found
|
|
81
|
+
*/
|
|
82
|
+
getUser<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIUser>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets a member option
|
|
85
|
+
* @param name The name of the option
|
|
86
|
+
* @param required Whether to throw an error if the option is not found
|
|
87
|
+
*/
|
|
88
|
+
getMember<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIInteractionDataResolvedGuildMember>;
|
|
89
|
+
/**
|
|
90
|
+
* Gets a role option
|
|
91
|
+
* @param name The name of the option
|
|
92
|
+
* @param required Whether to throw an error if the option is not found
|
|
93
|
+
*/
|
|
94
|
+
getRole<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIRole>;
|
|
95
|
+
/**
|
|
96
|
+
* Gets an attachment option
|
|
97
|
+
* @param name The name of the option
|
|
98
|
+
* @param required Whether to throw an error if the option is not found
|
|
99
|
+
*/
|
|
100
|
+
getAttachment<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIAttachment>;
|
|
101
|
+
/**
|
|
102
|
+
* Gets a mentionable option
|
|
103
|
+
* @param name The name of the option
|
|
104
|
+
* @param required Whether to throw an error if the option is not found
|
|
105
|
+
*/
|
|
106
|
+
getMentionable<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIUser | APIInteractionDataResolvedGuildMember | APIRole>;
|
|
57
107
|
/**
|
|
58
108
|
* Gets the target user for a context menu interaction
|
|
59
109
|
*/
|
|
60
110
|
getTargetUser(): APIUser;
|
|
61
|
-
|
|
62
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Gets the target member for a context menu interaction
|
|
113
|
+
* @param required Whether to throw an error if the member data is not present
|
|
114
|
+
*/
|
|
115
|
+
getTargetMember<Required extends boolean = false>(required?: Required): RequiredIf<Required, APIInteractionDataResolvedGuildMember>;
|
|
63
116
|
/**
|
|
64
117
|
* Gets the target message for a context menu interaction
|
|
65
118
|
*/
|
|
@@ -82,6 +135,8 @@ declare class InteractionOptionResolver {
|
|
|
82
135
|
};
|
|
83
136
|
private getTypedOption;
|
|
84
137
|
}
|
|
138
|
+
type If<Value extends boolean, TrueResult, FalseResult> = Value extends true ? TrueResult : Value extends false ? FalseResult : TrueResult | FalseResult;
|
|
139
|
+
type RequiredIf<Value extends boolean, ValueType, FallbackType = null> = If<Value, ValueType, ValueType | FallbackType>;
|
|
85
140
|
|
|
86
141
|
/**
|
|
87
142
|
* Namespace containing limits related to Discord channels.
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -28,38 +28,91 @@ declare class InteractionOptionResolver {
|
|
|
28
28
|
*/
|
|
29
29
|
private readonly subcommand;
|
|
30
30
|
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Gets an option by its name
|
|
33
|
+
* @param name The name of the option
|
|
34
|
+
* @param required Whether to throw an error if the option is not found
|
|
35
|
+
*/
|
|
36
|
+
get<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIApplicationCommandInteractionDataOption>;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the selected subcommand
|
|
39
|
+
* @param required Whether to throw an error if there is no subcommand
|
|
40
|
+
*/
|
|
41
|
+
getSubcommand<Required extends boolean = false>(required?: Required): RequiredIf<Required, string>;
|
|
42
|
+
/**
|
|
43
|
+
* Gets the selected subcommand group
|
|
44
|
+
* @param required Whether to throw an error if there is no subcommand group
|
|
45
|
+
*/
|
|
46
|
+
getSubcommandGroup<Required extends boolean = false>(required?: Required): RequiredIf<Required, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets a boolean option
|
|
49
|
+
* @param name The name of the option
|
|
50
|
+
* @param required Whether to throw an error if the option is not found
|
|
51
|
+
*/
|
|
52
|
+
getBoolean<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Gets a channel option
|
|
55
|
+
* @param name The name of the option
|
|
56
|
+
* @param required Whether to throw an error if the option is not found
|
|
57
|
+
*/
|
|
58
|
+
getChannel<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIInteractionDataResolvedChannel>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets a string option
|
|
61
|
+
* @param name The name of the option
|
|
62
|
+
* @param required Whether to throw an error if the option is not found
|
|
63
|
+
*/
|
|
64
|
+
getString<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets an integer option
|
|
67
|
+
* @param name The name of the option
|
|
68
|
+
* @param required Whether to throw an error if the option is not found
|
|
69
|
+
*/
|
|
70
|
+
getInteger<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, number>;
|
|
71
|
+
/**
|
|
72
|
+
* Gets a number option
|
|
73
|
+
* @param name The name of the option
|
|
74
|
+
* @param required Whether to throw an error if the option is not found
|
|
75
|
+
*/
|
|
76
|
+
getNumber<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, number>;
|
|
77
|
+
/**
|
|
78
|
+
* Gets a user option
|
|
79
|
+
* @param name The name of the option
|
|
80
|
+
* @param required Whether to throw an error if the option is not found
|
|
81
|
+
*/
|
|
82
|
+
getUser<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIUser>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets a member option
|
|
85
|
+
* @param name The name of the option
|
|
86
|
+
* @param required Whether to throw an error if the option is not found
|
|
87
|
+
*/
|
|
88
|
+
getMember<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIInteractionDataResolvedGuildMember>;
|
|
89
|
+
/**
|
|
90
|
+
* Gets a role option
|
|
91
|
+
* @param name The name of the option
|
|
92
|
+
* @param required Whether to throw an error if the option is not found
|
|
93
|
+
*/
|
|
94
|
+
getRole<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIRole>;
|
|
95
|
+
/**
|
|
96
|
+
* Gets an attachment option
|
|
97
|
+
* @param name The name of the option
|
|
98
|
+
* @param required Whether to throw an error if the option is not found
|
|
99
|
+
*/
|
|
100
|
+
getAttachment<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIAttachment>;
|
|
101
|
+
/**
|
|
102
|
+
* Gets a mentionable option
|
|
103
|
+
* @param name The name of the option
|
|
104
|
+
* @param required Whether to throw an error if the option is not found
|
|
105
|
+
*/
|
|
106
|
+
getMentionable<Required extends boolean = false>(name: string, required?: Required): RequiredIf<Required, APIUser | APIInteractionDataResolvedGuildMember | APIRole>;
|
|
57
107
|
/**
|
|
58
108
|
* Gets the target user for a context menu interaction
|
|
59
109
|
*/
|
|
60
110
|
getTargetUser(): APIUser;
|
|
61
|
-
|
|
62
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Gets the target member for a context menu interaction
|
|
113
|
+
* @param required Whether to throw an error if the member data is not present
|
|
114
|
+
*/
|
|
115
|
+
getTargetMember<Required extends boolean = false>(required?: Required): RequiredIf<Required, APIInteractionDataResolvedGuildMember>;
|
|
63
116
|
/**
|
|
64
117
|
* Gets the target message for a context menu interaction
|
|
65
118
|
*/
|
|
@@ -82,6 +135,8 @@ declare class InteractionOptionResolver {
|
|
|
82
135
|
};
|
|
83
136
|
private getTypedOption;
|
|
84
137
|
}
|
|
138
|
+
type If<Value extends boolean, TrueResult, FalseResult> = Value extends true ? TrueResult : Value extends false ? FalseResult : TrueResult | FalseResult;
|
|
139
|
+
type RequiredIf<Value extends boolean, ValueType, FallbackType = null> = If<Value, ValueType, ValueType | FallbackType>;
|
|
85
140
|
|
|
86
141
|
/**
|
|
87
142
|
* Namespace containing limits related to Discord channels.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -41,11 +41,6 @@ var _InteractionOptionResolver = class _InteractionOptionResolver {
|
|
|
41
41
|
this.hoistedOptions = this.hoistedOptions[0].options ?? [];
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Gets an option by its name
|
|
46
|
-
* @param name The name of the option
|
|
47
|
-
* @param required Whether to throw an error if the option is not found
|
|
48
|
-
*/
|
|
49
44
|
get(name, required = false) {
|
|
50
45
|
const option = this.hoistedOptions?.find((opt) => opt.name === name);
|
|
51
46
|
if (!option) {
|
|
@@ -56,112 +51,54 @@ var _InteractionOptionResolver = class _InteractionOptionResolver {
|
|
|
56
51
|
}
|
|
57
52
|
return option;
|
|
58
53
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Gets the selected subcommand
|
|
61
|
-
* @param required Whether to throw an error if there is no subcommand
|
|
62
|
-
*/
|
|
63
54
|
getSubcommand(required = true) {
|
|
64
55
|
if (required && !this.subcommand) {
|
|
65
56
|
throw new Error("A subcommand was not selected");
|
|
66
57
|
}
|
|
67
58
|
return this.subcommand;
|
|
68
59
|
}
|
|
69
|
-
/**
|
|
70
|
-
* Gets the selected subcommand group
|
|
71
|
-
* @param required Whether to throw an error if there is no subcommand group
|
|
72
|
-
*/
|
|
73
60
|
getSubcommandGroup(required = true) {
|
|
74
61
|
if (required && !this.group) {
|
|
75
62
|
throw new Error("A subcommand group was not selected");
|
|
76
63
|
}
|
|
77
64
|
return this.group;
|
|
78
65
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Gets a boolean option
|
|
81
|
-
* @param name The name of the option
|
|
82
|
-
* @param required Whether to throw an error if the option is not found
|
|
83
|
-
*/
|
|
84
66
|
getBoolean(name, required = false) {
|
|
85
67
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.Boolean, required);
|
|
86
68
|
return option?.value ?? null;
|
|
87
69
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Gets a channel option
|
|
90
|
-
* @param name The name of the option
|
|
91
|
-
* @param required Whether to throw an error if the option is not found
|
|
92
|
-
*/
|
|
93
70
|
getChannel(name, required = false) {
|
|
94
71
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.Channel, required);
|
|
95
72
|
return option && this.resolved && "channels" in this.resolved ? this.resolved.channels?.[option.value] ?? null : null;
|
|
96
73
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets a string option
|
|
99
|
-
* @param name The name of the option
|
|
100
|
-
* @param required Whether to throw an error if the option is not found
|
|
101
|
-
*/
|
|
102
74
|
getString(name, required = false) {
|
|
103
75
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.String, required);
|
|
104
76
|
return option?.value ?? null;
|
|
105
77
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Gets an integer option
|
|
108
|
-
* @param name The name of the option
|
|
109
|
-
* @param required Whether to throw an error if the option is not found
|
|
110
|
-
*/
|
|
111
78
|
getInteger(name, required = false) {
|
|
112
79
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.Integer, required);
|
|
113
80
|
return option?.value ?? null;
|
|
114
81
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Gets a number option
|
|
117
|
-
* @param name The name of the option
|
|
118
|
-
* @param required Whether to throw an error if the option is not found
|
|
119
|
-
*/
|
|
120
82
|
getNumber(name, required = false) {
|
|
121
83
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.Number, required);
|
|
122
84
|
return option?.value ?? null;
|
|
123
85
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Gets a user option
|
|
126
|
-
* @param name The name of the option
|
|
127
|
-
* @param required Whether to throw an error if the option is not found
|
|
128
|
-
*/
|
|
129
86
|
getUser(name, required = false) {
|
|
130
87
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.User, required);
|
|
131
88
|
return option && this.resolved && "users" in this.resolved ? this.resolved.users?.[option.value] ?? null : null;
|
|
132
89
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Gets a member option
|
|
135
|
-
* @param name The name of the option
|
|
136
|
-
* @param required Whether to throw an error if the option is not found
|
|
137
|
-
*/
|
|
138
90
|
getMember(name, required = false) {
|
|
139
91
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.User, required);
|
|
140
92
|
return option && this.resolved && "members" in this.resolved ? this.resolved.members?.[option.value] ?? null : null;
|
|
141
93
|
}
|
|
142
|
-
/**
|
|
143
|
-
* Gets a role option
|
|
144
|
-
* @param name The name of the option
|
|
145
|
-
* @param required Whether to throw an error if the option is not found
|
|
146
|
-
*/
|
|
147
94
|
getRole(name, required = false) {
|
|
148
95
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.Role, required);
|
|
149
96
|
return option && this.resolved && "roles" in this.resolved ? this.resolved.roles?.[option.value] ?? null : null;
|
|
150
97
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Gets an attachment option
|
|
153
|
-
* @param name The name of the option
|
|
154
|
-
* @param required Whether to throw an error if the option is not found
|
|
155
|
-
*/
|
|
156
98
|
getAttachment(name, required = false) {
|
|
157
99
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.Attachment, required);
|
|
158
100
|
return option && this.resolved && "attachments" in this.resolved ? this.resolved.attachments?.[option.value] ?? null : null;
|
|
159
101
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Gets a mentionable option
|
|
162
|
-
* @param name The name of the option
|
|
163
|
-
* @param required Whether to throw an error if the option is not found
|
|
164
|
-
*/
|
|
165
102
|
getMentionable(name, required = false) {
|
|
166
103
|
const option = this.getTypedOption(name, ApplicationCommandOptionType.Mentionable, required);
|
|
167
104
|
if (!option || !this.resolved) {
|
|
@@ -187,10 +124,6 @@ var _InteractionOptionResolver = class _InteractionOptionResolver {
|
|
|
187
124
|
}
|
|
188
125
|
return this.resolved.users[this.interaction.data.target_id];
|
|
189
126
|
}
|
|
190
|
-
/**
|
|
191
|
-
* Gets the target member for a context menu interaction
|
|
192
|
-
* @param required Whether to throw an error if the member data is not present
|
|
193
|
-
*/
|
|
194
127
|
getTargetMember(required = false) {
|
|
195
128
|
if (this.interaction.type !== InteractionType.ApplicationCommand || this.interaction.data.type !== ApplicationCommandType.User) {
|
|
196
129
|
throw new Error("This method can only be used on user context menu interactions");
|