11'use strict' ;
22
3+ const { isJSONEncodable } = require ( '@discordjs/builders' ) ;
34const { Collection } = require ( '@discordjs/collection' ) ;
45const ApplicationCommandPermissionsManager = require ( './ApplicationCommandPermissionsManager' ) ;
56const CachedManager = require ( './CachedManager' ) ;
@@ -54,6 +55,13 @@ class ApplicationCommandManager extends CachedManager {
5455 * @typedef {ApplicationCommand|Snowflake } ApplicationCommandResolvable
5556 */
5657
58+ /* eslint-disable max-len */
59+ /**
60+ * Data that resolves to the data of an ApplicationCommand
61+ * @typedef {ApplicationCommandData|APIApplicationCommand|SlashCommandBuilder|ContextMenuCommandBuilder } ApplicationCommandDataResolvable
62+ */
63+ /* eslint-enable max-len */
64+
5765 /**
5866 * Options used to fetch data from Discord
5967 * @typedef {Object } BaseFetchOptions
@@ -108,7 +116,7 @@ class ApplicationCommandManager extends CachedManager {
108116
109117 /**
110118 * Creates an application command.
111- * @param {ApplicationCommandData|APIApplicationCommand } command The command
119+ * @param {ApplicationCommandDataResolvable } command The command
112120 * @param {Snowflake } [guildId] The guild's id to create this command in,
113121 * ignored when using a {@link GuildApplicationCommandManager}
114122 * @returns {Promise<ApplicationCommand> }
@@ -130,7 +138,7 @@ class ApplicationCommandManager extends CachedManager {
130138
131139 /**
132140 * Sets all the commands for this application or guild.
133- * @param {ApplicationCommandData[]|APIApplicationCommand [] } commands The commands
141+ * @param {ApplicationCommandDataResolvable [] } commands The commands
134142 * @param {Snowflake } [guildId] The guild's id to create the commands in,
135143 * ignored when using a {@link GuildApplicationCommandManager}
136144 * @returns {Promise<Collection<Snowflake, ApplicationCommand>> }
@@ -160,7 +168,7 @@ class ApplicationCommandManager extends CachedManager {
160168 /**
161169 * Edits an application command.
162170 * @param {ApplicationCommandResolvable } command The command to edit
163- * @param {Partial<ApplicationCommandData|APIApplicationCommand > } data The data to update the command with
171+ * @param {Partial<ApplicationCommandDataResolvable > } data The data to update the command with
164172 * @param {Snowflake } [guildId] The guild's id where the command registered,
165173 * ignored when using a {@link GuildApplicationCommandManager}
166174 * @returns {Promise<ApplicationCommand> }
@@ -207,11 +215,13 @@ class ApplicationCommandManager extends CachedManager {
207215
208216 /**
209217 * Transforms an {@link ApplicationCommandData} object into something that can be used with the API.
210- * @param {ApplicationCommandData|APIApplicationCommand } command The command to transform
218+ * @param {ApplicationCommandDataResolvable } command The command to transform
211219 * @returns {APIApplicationCommand }
212220 * @private
213221 */
214222 static transformCommand ( command ) {
223+ if ( isJSONEncodable ( command ) ) return command . toJSON ( ) ;
224+
215225 let default_member_permissions ;
216226
217227 if ( 'default_member_permissions' in command ) {
@@ -241,3 +251,13 @@ class ApplicationCommandManager extends CachedManager {
241251}
242252
243253module . exports = ApplicationCommandManager ;
254+
255+ /**
256+ * @external SlashCommandBuilder
257+ * @see {@link https://discord.js.org/#/docs/builders/main/class/SlashCommandBuilder }
258+ */
259+
260+ /**
261+ * @external ContextMenuCommandBuilder
262+ * @see {@link https://discord.js.org/#/docs/builders/main/class/ContextMenuCommandBuilder }
263+ */
0 commit comments