diff --git a/src/managers/ApplicationCommandManager.js b/src/managers/ApplicationCommandManager.js index dbc83dcb2c0b..c053382f3a9a 100644 --- a/src/managers/ApplicationCommandManager.js +++ b/src/managers/ApplicationCommandManager.js @@ -100,7 +100,7 @@ class ApplicationCommandManager extends CachedManager { /** * Creates an application command. - * @param {ApplicationCommandData} command The command + * @param {ApplicationCommandData|APIApplicationCommand} command The command * @param {Snowflake} [guildId] The guild's id to create this command in, * ignored when using a {@link GuildApplicationCommandManager} * @returns {Promise} @@ -122,7 +122,7 @@ class ApplicationCommandManager extends CachedManager { /** * Sets all the commands for this application or guild. - * @param {ApplicationCommandData[]} commands The commands + * @param {ApplicationCommandData[]|APIApplicationCommand[]} commands The commands * @param {Snowflake} [guildId] The guild's id to create the commands in, * ignored when using a {@link GuildApplicationCommandManager} * @returns {Promise>} @@ -155,7 +155,7 @@ class ApplicationCommandManager extends CachedManager { /** * Edits an application command. * @param {ApplicationCommandResolvable} command The command to edit - * @param {ApplicationCommandData} data The data to update the command with + * @param {ApplicationCommandData|APIApplicationCommand} data The data to update the command with * @param {Snowflake} [guildId] The guild's id where the command registered, * ignored when using a {@link GuildApplicationCommandManager} * @returns {Promise} @@ -171,7 +171,9 @@ class ApplicationCommandManager extends CachedManager { const id = this.resolveId(command); if (!id) throw new TypeError('INVALID_TYPE', 'command', 'ApplicationCommandResolvable'); - const patched = await this.commandPath({ id, guildId }).patch({ data: this.constructor.transformCommand(data) }); + const patched = await this.commandPath({ id, guildId }).patch({ + data: this.constructor.transformCommand(data), + }); return this._add(patched, !guildId, guildId); } @@ -200,7 +202,7 @@ class ApplicationCommandManager extends CachedManager { /** * Transforms an {@link ApplicationCommandData} object into something that can be used with the API. - * @param {ApplicationCommandData} command The command to transform + * @param {ApplicationCommandData|APIApplicationCommand} command The command to transform * @returns {APIApplicationCommand} * @private */ @@ -210,7 +212,7 @@ class ApplicationCommandManager extends CachedManager { description: command.description, type: typeof command.type === 'number' ? command.type : ApplicationCommandTypes[command.type], options: command.options?.map(o => ApplicationCommand.transformOption(o)), - default_permission: command.defaultPermission, + default_permission: command.defaultPermission ?? command.default_permission, }; } } diff --git a/typings/index.d.ts b/typings/index.d.ts index e1f8bf8d4765..61251c5fa5ba 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -45,6 +45,7 @@ import { APIUser, GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData, + RESTPostAPIApplicationCommandsJSONBody, Snowflake, } from 'discord-api-types/v9'; import { EventEmitter } from 'events'; @@ -237,6 +238,8 @@ export class ApplicationCommand extends Base { enforceOptionorder?: boolean, ): boolean; private static transformOption(option: ApplicationCommandOptionData, received?: boolean): unknown; + private static transformCommand(command: ApplicationCommandData): RESTPostAPIApplicationCommandsJSONBody; + private static isAPICommandData(command: object): command is RESTPostAPIApplicationCommandsJSONBody; } export type ApplicationResolvable = Application | Activity | Snowflake; @@ -2400,6 +2403,8 @@ export abstract class CachedManager extends DataManager, PermissionsOptionsExtras = { guild: GuildResolvable }, @@ -2414,13 +2419,16 @@ export class ApplicationCommandManager< null >; private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown; - public create(command: ApplicationCommandData): Promise; - public create(command: ApplicationCommandData, guildId: Snowflake): Promise; + public create(command: ApplicationCommandDataResolvable): Promise; + public create(command: ApplicationCommandDataResolvable, guildId: Snowflake): Promise; public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise; - public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise; public edit( command: ApplicationCommandResolvable, - data: ApplicationCommandData, + data: ApplicationCommandDataResolvable, + ): Promise; + public edit( + command: ApplicationCommandResolvable, + data: ApplicationCommandDataResolvable, guildId: Snowflake, ): Promise; public fetch( @@ -2432,9 +2440,9 @@ export class ApplicationCommandManager< id?: Snowflake, options?: FetchApplicationCommandOptions, ): Promise>; - public set(commands: ApplicationCommandData[]): Promise>; + public set(commands: ApplicationCommandDataResolvable[]): Promise>; public set( - commands: ApplicationCommandData[], + commands: ApplicationCommandDataResolvable[], guildId: Snowflake, ): Promise>; private static transformCommand( @@ -2502,12 +2510,15 @@ export class ChannelManager extends CachedManager { public constructor(guild: Guild, iterable?: Iterable); public guild: Guild; - public create(command: ApplicationCommandData): Promise; + public create(command: ApplicationCommandDataResolvable): Promise; public delete(command: ApplicationCommandResolvable): Promise; - public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise; + public edit( + command: ApplicationCommandResolvable, + data: ApplicationCommandDataResolvable, + ): Promise; public fetch(id: Snowflake, options?: BaseFetchOptions): Promise; public fetch(id?: undefined, options?: BaseFetchOptions): Promise>; - public set(commands: ApplicationCommandData[]): Promise>; + public set(commands: ApplicationCommandDataResolvable[]): Promise>; } export class GuildChannelManager extends CachedManager<