mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
feat: right-clickybois (context menu support for ApplicationCommand and CommandInteraction) (#6176)
Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
6
typings/enums.d.ts
vendored
6
typings/enums.d.ts
vendored
@@ -10,6 +10,12 @@ export enum ActivityTypes {
|
||||
COMPETING = 5,
|
||||
}
|
||||
|
||||
export enum ApplicationCommandTypes {
|
||||
CHAT_INPUT = 1,
|
||||
USER = 2,
|
||||
MESSAGE = 3,
|
||||
}
|
||||
|
||||
export enum ApplicationCommandOptionTypes {
|
||||
SUB_COMMAND = 1,
|
||||
SUB_COMMAND_GROUP = 2,
|
||||
|
||||
85
typings/index.d.ts
vendored
85
typings/index.d.ts
vendored
@@ -21,6 +21,7 @@ import {
|
||||
APIApplicationCommand,
|
||||
APIApplicationCommandInteractionData,
|
||||
APIApplicationCommandInteractionDataOption,
|
||||
APIApplicationCommandOption,
|
||||
APIApplicationCommandPermission,
|
||||
APIAuditLogChange,
|
||||
APIEmoji,
|
||||
@@ -48,6 +49,7 @@ import {
|
||||
ActivityTypes,
|
||||
ApplicationCommandOptionTypes,
|
||||
ApplicationCommandPermissionTypes,
|
||||
ApplicationCommandTypes,
|
||||
ChannelTypes,
|
||||
DefaultMessageNotificationLevels,
|
||||
ExplicitContentFilterLevels,
|
||||
@@ -209,6 +211,7 @@ export class ApplicationCommand<PermissionsFetchType = {}> extends Base {
|
||||
Guild | null,
|
||||
Snowflake
|
||||
>;
|
||||
public type: ApplicationCommandType;
|
||||
public delete(): Promise<ApplicationCommand<PermissionsFetchType>>;
|
||||
public edit(data: ApplicationCommandData): Promise<ApplicationCommand<PermissionsFetchType>>;
|
||||
private static transformOption(option: ApplicationCommandOptionData, received?: boolean): unknown;
|
||||
@@ -240,6 +243,30 @@ export class BaseClient extends EventEmitter {
|
||||
public toJSON(...props: Record<string, boolean | string>[]): unknown;
|
||||
}
|
||||
|
||||
export abstract class BaseCommandInteraction extends Interaction {
|
||||
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
|
||||
public readonly channel: TextBasedChannels | null;
|
||||
public channelId: Snowflake;
|
||||
public commandId: Snowflake;
|
||||
public commandName: string;
|
||||
public deferred: boolean;
|
||||
public ephemeral: boolean | null;
|
||||
public replied: boolean;
|
||||
public webhook: InteractionWebhook;
|
||||
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
|
||||
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
|
||||
public deleteReply(): Promise<void>;
|
||||
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message | APIMessage>;
|
||||
public fetchReply(): Promise<Message | APIMessage>;
|
||||
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message | APIMessage>;
|
||||
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
|
||||
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
|
||||
private transformOption(
|
||||
option: APIApplicationCommandOption,
|
||||
resolved: APIApplicationCommandInteractionData['resolved'],
|
||||
): CommandInteractionOption;
|
||||
}
|
||||
|
||||
export abstract class BaseGuild extends Base {
|
||||
public constructor(client: Client, data: RawBaseGuildData);
|
||||
public readonly createdAt: Date;
|
||||
@@ -494,30 +521,8 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
|
||||
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;
|
||||
}
|
||||
|
||||
export class CommandInteraction extends Interaction {
|
||||
public constructor(client: Client, data: RawCommandInteractionData);
|
||||
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
|
||||
public readonly channel: TextBasedChannels | null;
|
||||
public channelId: Snowflake;
|
||||
public commandId: Snowflake;
|
||||
public commandName: string;
|
||||
public deferred: boolean;
|
||||
public ephemeral: boolean | null;
|
||||
export class CommandInteraction extends BaseCommandInteraction {
|
||||
public options: CommandInteractionOptionResolver;
|
||||
public replied: boolean;
|
||||
public webhook: InteractionWebhook;
|
||||
public deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
|
||||
public deferReply(options?: InteractionDeferReplyOptions): Promise<void>;
|
||||
public deleteReply(): Promise<void>;
|
||||
public editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise<Message | APIMessage>;
|
||||
public fetchReply(): Promise<Message | APIMessage>;
|
||||
public followUp(options: string | MessagePayload | InteractionReplyOptions): Promise<Message | APIMessage>;
|
||||
public reply(options: InteractionReplyOptions & { fetchReply: true }): Promise<Message | APIMessage>;
|
||||
public reply(options: string | MessagePayload | InteractionReplyOptions): Promise<void>;
|
||||
private transformOption(
|
||||
option: APIApplicationCommandInteractionDataOption,
|
||||
resolved: APIApplicationCommandInteractionData['resolved'],
|
||||
): CommandInteractionOption;
|
||||
}
|
||||
|
||||
export class CommandInteractionOptionResolver {
|
||||
@@ -571,6 +576,15 @@ export class CommandInteractionOptionResolver {
|
||||
name: string,
|
||||
required?: boolean,
|
||||
): NonNullable<CommandInteractionOption['member' | 'role' | 'user']> | null;
|
||||
public getMessage(name: string, required: true): NonNullable<CommandInteractionOption['message']>;
|
||||
public getMessage(name: string, required?: boolean): NonNullable<CommandInteractionOption['message']> | null;
|
||||
}
|
||||
|
||||
export class ContextMenuInteraction extends BaseCommandInteraction {
|
||||
public options: CommandInteractionOptionResolver;
|
||||
public targetId: Snowflake;
|
||||
public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>;
|
||||
private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[];
|
||||
}
|
||||
|
||||
export class DataResolver extends null {
|
||||
@@ -976,6 +990,7 @@ export class Interaction extends Base {
|
||||
public inGuild(): this is this & { guildId: Snowflake; member: GuildMember | APIInteractionGuildMember };
|
||||
public isButton(): this is ButtonInteraction;
|
||||
public isCommand(): this is CommandInteraction;
|
||||
public isContextMenu(): this is ContextMenuInteraction;
|
||||
public isMessageComponent(): this is MessageComponentInteraction;
|
||||
public isSelectMenu(): this is SelectMenuInteraction;
|
||||
}
|
||||
@@ -2256,11 +2271,11 @@ export abstract class CachedManager<K, Holds, R> extends DataManager<K, Holds, R
|
||||
}
|
||||
|
||||
export class ApplicationCommandManager<
|
||||
ApplicationCommandType = ApplicationCommand<{ guild: GuildResolvable }>,
|
||||
ApplicationCommandScope = ApplicationCommand<{ guild: GuildResolvable }>,
|
||||
PermissionsOptionsExtras = { guild: GuildResolvable },
|
||||
PermissionsGuildType = null,
|
||||
> extends CachedManager<Snowflake, ApplicationCommandType, ApplicationCommandResolvable> {
|
||||
public constructor(client: Client, iterable?: Iterable<RawApplicationCommandData>);
|
||||
> extends CachedManager<Snowflake, ApplicationCommandScope, ApplicationCommandResolvable> {
|
||||
public constructor(client: Client, iterable?: Iterable<unknown>);
|
||||
public permissions: ApplicationCommandPermissionsManager<
|
||||
{ command?: ApplicationCommandResolvable } & PermissionsOptionsExtras,
|
||||
{ command: ApplicationCommandResolvable } & PermissionsOptionsExtras,
|
||||
@@ -2269,10 +2284,10 @@ export class ApplicationCommandManager<
|
||||
null
|
||||
>;
|
||||
private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown;
|
||||
public create(command: ApplicationCommandData): Promise<ApplicationCommandType>;
|
||||
public create(command: ApplicationCommandData): Promise<ApplicationCommandScope>;
|
||||
public create(command: ApplicationCommandData, guildId: Snowflake): Promise<ApplicationCommand>;
|
||||
public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise<ApplicationCommandType | null>;
|
||||
public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise<ApplicationCommandType>;
|
||||
public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise<ApplicationCommandScope | null>;
|
||||
public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise<ApplicationCommandScope>;
|
||||
public edit(
|
||||
command: ApplicationCommandResolvable,
|
||||
data: ApplicationCommandData,
|
||||
@@ -2282,12 +2297,12 @@ export class ApplicationCommandManager<
|
||||
id: Snowflake,
|
||||
options: FetchApplicationCommandOptions & { guildId: Snowflake },
|
||||
): Promise<ApplicationCommand>;
|
||||
public fetch(id: Snowflake, options?: FetchApplicationCommandOptions): Promise<ApplicationCommandType>;
|
||||
public fetch(id: Snowflake, options?: FetchApplicationCommandOptions): Promise<ApplicationCommandScope>;
|
||||
public fetch(
|
||||
id?: Snowflake,
|
||||
options?: FetchApplicationCommandOptions,
|
||||
): Promise<Collection<Snowflake, ApplicationCommandType>>;
|
||||
public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommandType>>;
|
||||
): Promise<Collection<Snowflake, ApplicationCommandScope>>;
|
||||
public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommandScope>>;
|
||||
public set(
|
||||
commands: ApplicationCommandData[],
|
||||
guildId: Snowflake,
|
||||
@@ -2868,7 +2883,8 @@ export interface ApplicationAsset {
|
||||
|
||||
export interface ApplicationCommandData {
|
||||
name: string;
|
||||
description: string;
|
||||
description?: string;
|
||||
type?: ApplicationCommandType | ApplicationCommandTypes;
|
||||
options?: ApplicationCommandOptionData[];
|
||||
defaultPermission?: boolean;
|
||||
}
|
||||
@@ -2892,6 +2908,8 @@ export interface ApplicationCommandOptionChoice {
|
||||
value: string | number;
|
||||
}
|
||||
|
||||
export type ApplicationCommandType = keyof typeof ApplicationCommandTypes;
|
||||
|
||||
export type ApplicationCommandOptionType = keyof typeof ApplicationCommandOptionTypes;
|
||||
|
||||
export interface ApplicationCommandPermissionData {
|
||||
@@ -3234,6 +3252,7 @@ export interface CommandInteractionOption {
|
||||
member?: GuildMember | APIInteractionDataResolvedGuildMember;
|
||||
channel?: GuildChannel | APIInteractionDataResolvedChannel;
|
||||
role?: Role | APIRole;
|
||||
message?: Message | APIMessage;
|
||||
}
|
||||
|
||||
export interface ConstantsClientApplicationAssetTypes {
|
||||
|
||||
@@ -610,17 +610,17 @@ declare const applicationCommandData: ApplicationCommandData;
|
||||
declare const applicationCommandResolvable: ApplicationCommandResolvable;
|
||||
declare const applicationCommandManager: ApplicationCommandManager;
|
||||
{
|
||||
type ApplicationCommandType = ApplicationCommand<{ guild: GuildResolvable }>;
|
||||
type ApplicationCommandScope = ApplicationCommand<{ guild: GuildResolvable }>;
|
||||
|
||||
assertType<Promise<ApplicationCommandType>>(applicationCommandManager.create(applicationCommandData));
|
||||
assertType<Promise<ApplicationCommandScope>>(applicationCommandManager.create(applicationCommandData));
|
||||
assertType<Promise<ApplicationCommand>>(applicationCommandManager.create(applicationCommandData, '0'));
|
||||
assertType<Promise<ApplicationCommandType>>(
|
||||
assertType<Promise<ApplicationCommandScope>>(
|
||||
applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData),
|
||||
);
|
||||
assertType<Promise<ApplicationCommand>>(
|
||||
applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0'),
|
||||
);
|
||||
assertType<Promise<Collection<Snowflake, ApplicationCommandType>>>(
|
||||
assertType<Promise<Collection<Snowflake, ApplicationCommandScope>>>(
|
||||
applicationCommandManager.set([applicationCommandData]),
|
||||
);
|
||||
assertType<Promise<Collection<Snowflake, ApplicationCommand>>>(
|
||||
|
||||
Reference in New Issue
Block a user