fix(applicationcommandmanager): explicitly allow passing builders to methods (v13) (#8229)

This commit is contained in:
Almeida
2022-07-05 10:12:13 +01:00
committed by GitHub
parent f704b261c0
commit f457cdd2de
3 changed files with 48 additions and 9 deletions

15
typings/index.d.ts vendored
View File

@@ -3,13 +3,16 @@ import {
bold,
channelMention,
codeBlock,
ContextMenuCommandBuilder,
formatEmoji,
hideLinkEmbed,
hyperlink,
inlineCode,
italic,
JSONEncodable,
quote,
roleMention,
SlashCommandBuilder,
spoiler,
strikethrough,
time,
@@ -3065,7 +3068,11 @@ export abstract class CachedManager<K, Holds, R> extends DataManager<K, Holds, R
private _add(data: unknown, cache?: boolean, { id, extras }?: { id: K; extras: unknown[] }): Holds;
}
export type ApplicationCommandDataResolvable = ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody;
export type ApplicationCommandDataResolvable =
| ApplicationCommandData
| RESTPostAPIApplicationCommandsJSONBody
| SlashCommandBuilder
| ContextMenuCommandBuilder;
export class ApplicationCommandManager<
ApplicationCommandScope = ApplicationCommand<{ guild: GuildResolvable }>,
@@ -3107,9 +3114,7 @@ export class ApplicationCommandManager<
commands: ApplicationCommandDataResolvable[],
guildId: Snowflake,
): Promise<Collection<Snowflake, ApplicationCommand>>;
private static transformCommand(
command: ApplicationCommandData,
): Omit<APIApplicationCommand, 'id' | 'application_id' | 'guild_id'>;
private static transformCommand(command: ApplicationCommandDataResolvable): RESTPostAPIApplicationCommandsJSONBody;
}
export class ApplicationCommandPermissionsManager<
@@ -3178,7 +3183,7 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager<Ap
public delete(command: ApplicationCommandResolvable): Promise<ApplicationCommand | null>;
public edit(
command: ApplicationCommandResolvable,
data: ApplicationCommandDataResolvable,
data: Partial<ApplicationCommandDataResolvable>,
): Promise<ApplicationCommand>;
public fetch(id: Snowflake, options?: FetchGuildApplicationCommandFetchOptions): Promise<ApplicationCommand>;
public fetch(options: FetchGuildApplicationCommandFetchOptions): Promise<Collection<Snowflake, ApplicationCommand>>;

View File

@@ -100,6 +100,7 @@ import {
} from '.';
import type { ApplicationCommandOptionTypes } from './enums';
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
// Test type transformation:
declare const serialize: <T>(value: T) => Serialized<T>;
@@ -128,6 +129,9 @@ const testUserId = '987654321098765432'; // example id
const globalCommandId = '123456789012345678'; // example id
const guildCommandId = '234567890123456789'; // example id
declare const slashCommandBuilder: SlashCommandBuilder;
declare const contextMenuCommandBuilder: ContextMenuCommandBuilder;
client.on('ready', async () => {
console.log(`Client is logged in as ${client.user!.tag} and ready!`);
@@ -144,6 +148,16 @@ client.on('ready', async () => {
const guildCommandFromGlobal = await client.application?.commands.fetch(guildCommandId, { guildId: testGuildId });
const guildCommandFromGuild = await client.guilds.cache.get(testGuildId)?.commands.fetch(guildCommandId);
await client.application?.commands.create(slashCommandBuilder);
await client.application?.commands.create(contextMenuCommandBuilder);
await guild.commands.create(slashCommandBuilder);
await guild.commands.create(contextMenuCommandBuilder);
await client.application?.commands.edit(globalCommandId, slashCommandBuilder);
await client.application?.commands.edit(globalCommandId, contextMenuCommandBuilder);
await guild.commands.edit(guildCommandId, slashCommandBuilder);
await guild.commands.edit(guildCommandId, contextMenuCommandBuilder);
await client.application?.commands.edit(globalCommandId, { defaultMemberPermissions: null });
await globalCommand?.edit({ defaultMemberPermissions: null });
await globalCommand?.setDefaultMemberPermissions(null);