mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
types(MessageComponentInteraction): Ensure component is not null (#7099)
This commit is contained in:
20
typings/index.d.ts
vendored
20
typings/index.d.ts
vendored
@@ -448,6 +448,13 @@ export class BitField<S extends string, N extends number | bigint = number> {
|
||||
|
||||
export class ButtonInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
|
||||
private constructor(client: Client, data: RawMessageButtonInteractionData);
|
||||
public readonly component: CacheTypeReducer<
|
||||
Cached,
|
||||
MessageButton,
|
||||
APIButtonComponent,
|
||||
MessageButton | APIButtonComponent,
|
||||
MessageButton | APIButtonComponent
|
||||
>;
|
||||
public componentType: 'BUTTON';
|
||||
public inGuild(): this is ButtonInteraction<'present'>;
|
||||
public inCachedGuild(): this is ButtonInteraction<'cached'>;
|
||||
@@ -1535,8 +1542,10 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
||||
public readonly component: CacheTypeReducer<
|
||||
Cached,
|
||||
MessageActionRowComponent,
|
||||
Exclude<APIMessageComponent, APIActionRowComponent>
|
||||
> | null;
|
||||
Exclude<APIMessageComponent, APIActionRowComponent>,
|
||||
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent>,
|
||||
MessageActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent>
|
||||
>;
|
||||
public componentType: Exclude<MessageComponentType, 'ACTION_ROW'>;
|
||||
public customId: string;
|
||||
public channelId: Snowflake;
|
||||
@@ -1871,6 +1880,13 @@ export class Role extends Base {
|
||||
|
||||
export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
|
||||
public constructor(client: Client, data: RawMessageSelectMenuInteractionData);
|
||||
public readonly component: CacheTypeReducer<
|
||||
Cached,
|
||||
MessageSelectMenu,
|
||||
APISelectMenuComponent,
|
||||
MessageSelectMenu | APISelectMenuComponent,
|
||||
MessageSelectMenu | APISelectMenuComponent
|
||||
>;
|
||||
public componentType: 'SELECT_MENU';
|
||||
public values: string[];
|
||||
public inGuild(): this is SelectMenuInteraction<'present'>;
|
||||
|
||||
@@ -7,6 +7,8 @@ import type {
|
||||
APIInteractionDataResolvedGuildMember,
|
||||
APIInteractionDataResolvedChannel,
|
||||
APIRole,
|
||||
APIButtonComponent,
|
||||
APISelectMenuComponent,
|
||||
} from 'discord-api-types/v9';
|
||||
import { AuditLogEvent } from 'discord-api-types/v9';
|
||||
import {
|
||||
@@ -85,6 +87,8 @@ import {
|
||||
StageInstance,
|
||||
Sticker,
|
||||
Emoji,
|
||||
MessageActionRowComponent,
|
||||
MessageSelectMenu,
|
||||
} from '.';
|
||||
import type { ApplicationCommandOptionTypes } from './enums';
|
||||
import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd';
|
||||
@@ -955,16 +959,20 @@ client.on('interactionCreate', async interaction => {
|
||||
|
||||
if (interaction.isButton()) {
|
||||
expectType<ButtonInteraction>(interaction);
|
||||
expectType<MessageButton | APIButtonComponent>(interaction.component);
|
||||
if (interaction.inCachedGuild()) {
|
||||
expectAssignable<ButtonInteraction>(interaction);
|
||||
expectType<MessageButton>(interaction.component);
|
||||
expectType<Guild>(interaction.guild);
|
||||
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
||||
} else if (interaction.inRawGuild()) {
|
||||
expectAssignable<ButtonInteraction>(interaction);
|
||||
expectType<APIButtonComponent>(interaction.component);
|
||||
expectType<null>(interaction.guild);
|
||||
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
} else if (interaction.inGuild()) {
|
||||
expectAssignable<ButtonInteraction>(interaction);
|
||||
expectType<MessageButton | APIButtonComponent>(interaction.component);
|
||||
expectAssignable<Guild | null>(interaction.guild);
|
||||
expectType<Promise<APIMessage | Message>>(interaction.reply({ fetchReply: true }));
|
||||
}
|
||||
@@ -972,16 +980,20 @@ client.on('interactionCreate', async interaction => {
|
||||
|
||||
if (interaction.isMessageComponent()) {
|
||||
expectType<MessageComponentInteraction>(interaction);
|
||||
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
||||
if (interaction.inCachedGuild()) {
|
||||
expectAssignable<MessageComponentInteraction>(interaction);
|
||||
expectType<MessageActionRowComponent>(interaction.component);
|
||||
expectType<Guild>(interaction.guild);
|
||||
expectAssignable<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
||||
} else if (interaction.inRawGuild()) {
|
||||
expectAssignable<MessageComponentInteraction>(interaction);
|
||||
expectType<APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
||||
expectType<null>(interaction.guild);
|
||||
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
} else if (interaction.inGuild()) {
|
||||
expectAssignable<MessageComponentInteraction>(interaction);
|
||||
expectType<MessageActionRowComponent | APIButtonComponent | APISelectMenuComponent>(interaction.component);
|
||||
expectType<Guild | null>(interaction.guild);
|
||||
expectType<Promise<APIMessage | Message>>(interaction.reply({ fetchReply: true }));
|
||||
}
|
||||
@@ -989,16 +1001,20 @@ client.on('interactionCreate', async interaction => {
|
||||
|
||||
if (interaction.isSelectMenu()) {
|
||||
expectType<SelectMenuInteraction>(interaction);
|
||||
expectType<MessageSelectMenu | APISelectMenuComponent>(interaction.component);
|
||||
if (interaction.inCachedGuild()) {
|
||||
expectAssignable<SelectMenuInteraction>(interaction);
|
||||
expectType<MessageSelectMenu>(interaction.component);
|
||||
expectType<Guild>(interaction.guild);
|
||||
expectType<Promise<Message<true>>>(interaction.reply({ fetchReply: true }));
|
||||
} else if (interaction.inRawGuild()) {
|
||||
expectAssignable<SelectMenuInteraction>(interaction);
|
||||
expectType<APISelectMenuComponent>(interaction.component);
|
||||
expectType<null>(interaction.guild);
|
||||
expectType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
} else if (interaction.inGuild()) {
|
||||
expectAssignable<SelectMenuInteraction>(interaction);
|
||||
expectType<MessageSelectMenu | APISelectMenuComponent>(interaction.component);
|
||||
expectType<Guild | null>(interaction.guild);
|
||||
expectType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user