mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
typings: cache types cleanup (#6867)
Co-authored-by: Almeida <almeidx@pm.me> Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
||||
APIPartialChannel,
|
||||
APIPartialGuild,
|
||||
APIInteractionDataResolvedGuildMember,
|
||||
APIInteractionDataResolvedChannel,
|
||||
APIRole,
|
||||
} from 'discord-api-types/v9';
|
||||
import {
|
||||
ApplicationCommand,
|
||||
@@ -33,19 +35,17 @@ import {
|
||||
DMChannel,
|
||||
Guild,
|
||||
GuildApplicationCommandManager,
|
||||
CachedInteraction,
|
||||
GuildChannel,
|
||||
GuildChannelManager,
|
||||
GuildEmoji,
|
||||
GuildEmojiManager,
|
||||
GuildMember,
|
||||
GuildMessage,
|
||||
GuildResolvable,
|
||||
GuildTextBasedChannel,
|
||||
GuildTextChannelResolvable,
|
||||
Intents,
|
||||
Interaction,
|
||||
InteractionCollector,
|
||||
InteractionResponses,
|
||||
LimitedCollection,
|
||||
Message,
|
||||
MessageActionRow,
|
||||
@@ -77,7 +77,6 @@ import {
|
||||
Typing,
|
||||
User,
|
||||
VoiceChannel,
|
||||
CachedMessage,
|
||||
} from '.';
|
||||
import { ApplicationCommandOptionTypes } from './enums';
|
||||
|
||||
@@ -498,13 +497,13 @@ client.on('messageCreate', async message => {
|
||||
assertIsMessage(channel.send({ embeds: [embed], files: [attachment] }));
|
||||
|
||||
if (message.inGuild()) {
|
||||
assertType<CachedMessage>(message);
|
||||
assertType<Message<true>>(message);
|
||||
const component = await message.awaitMessageComponent({ componentType: 'BUTTON' });
|
||||
assertType<InteractionResponses<'cached'>>(component);
|
||||
assertType<Promise<CachedMessage>>(component.reply({ fetchReply: true }));
|
||||
assertType<ButtonInteraction<'cached'>>(component);
|
||||
assertType<Message<true>>(await component.reply({ fetchReply: true }));
|
||||
|
||||
const buttonCollector = message.createMessageComponentCollector({ componentType: 'BUTTON' });
|
||||
assertType<InteractionCollector<CachedInteraction<ButtonInteraction>>>(buttonCollector);
|
||||
assertType<InteractionCollector<ButtonInteraction<'cached'>>>(buttonCollector);
|
||||
assertType<GuildTextBasedChannel>(message.channel);
|
||||
}
|
||||
|
||||
@@ -897,14 +896,11 @@ declare const booleanValue: boolean;
|
||||
if (interaction.inGuild()) assertType<Snowflake>(interaction.guildId);
|
||||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
const consumeCachedCommand = (_i: CachedInteraction<CommandInteraction>) => {};
|
||||
const consumeCachedInteraction = (_i: CachedInteraction<Interaction>) => {};
|
||||
|
||||
if (interaction.inCachedGuild()) {
|
||||
assertType<GuildMember>(interaction.member);
|
||||
// @ts-expect-error
|
||||
consumeCachedCommand(interaction);
|
||||
consumeCachedInteraction(interaction);
|
||||
assertType<CommandInteraction<'cached'>>(interaction);
|
||||
assertType<Interaction>(interaction);
|
||||
} else if (interaction.inRawGuild()) {
|
||||
assertType<APIInteractionGuildMember>(interaction.member);
|
||||
// @ts-expect-error
|
||||
@@ -920,7 +916,7 @@ client.on('interactionCreate', async interaction => {
|
||||
if (interaction.inCachedGuild()) {
|
||||
assertType<ContextMenuInteraction>(interaction);
|
||||
assertType<Guild>(interaction.guild);
|
||||
consumeCachedCommand(interaction);
|
||||
assertType<CommandInteraction<'cached'>>(interaction);
|
||||
} else if (interaction.inRawGuild()) {
|
||||
assertType<ContextMenuInteraction>(interaction);
|
||||
assertType<null>(interaction.guild);
|
||||
@@ -989,18 +985,26 @@ client.on('interactionCreate', async interaction => {
|
||||
assertType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
assertType<APIInteractionDataResolvedGuildMember | null>(interaction.options.getMember('test'));
|
||||
assertType<APIInteractionDataResolvedGuildMember>(interaction.options.getMember('test', true));
|
||||
|
||||
assertType<APIInteractionDataResolvedChannel>(interaction.options.getChannel('test', true));
|
||||
assertType<APIRole>(interaction.options.getRole('test', true));
|
||||
assertType<APIMessage>(interaction.options.getMessage('test', true));
|
||||
} else if (interaction.inCachedGuild()) {
|
||||
const msg = await interaction.reply({ fetchReply: true });
|
||||
const btn = await msg.awaitMessageComponent({ componentType: 'BUTTON' });
|
||||
|
||||
assertType<Message>(msg);
|
||||
assertType<CachedInteraction<ButtonInteraction>>(btn);
|
||||
assertType<ButtonInteraction<'cached'>>(btn);
|
||||
|
||||
consumeCachedCommand(interaction);
|
||||
assertType<CommandInteraction<'cached'>>(interaction);
|
||||
assertType<GuildMember>(interaction.options.getMember('test', true));
|
||||
assertType<GuildMember | null>(interaction.options.getMember('test'));
|
||||
assertType<CommandInteraction>(interaction);
|
||||
assertType<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
||||
|
||||
assertType<GuildChannel | ThreadChannel>(interaction.options.getChannel('test', true));
|
||||
assertType<Role>(interaction.options.getRole('test', true));
|
||||
assertType<Message>(interaction.options.getMessage('test', true));
|
||||
} else {
|
||||
// @ts-expect-error
|
||||
consumeCachedCommand(interaction);
|
||||
@@ -1008,6 +1012,12 @@ client.on('interactionCreate', async interaction => {
|
||||
assertType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
assertType<APIInteractionDataResolvedGuildMember | GuildMember | null>(interaction.options.getMember('test'));
|
||||
assertType<APIInteractionDataResolvedGuildMember | GuildMember>(interaction.options.getMember('test', true));
|
||||
|
||||
assertType<GuildChannel | ThreadChannel | APIInteractionDataResolvedChannel>(
|
||||
interaction.options.getChannel('test', true),
|
||||
);
|
||||
assertType<APIRole | Role>(interaction.options.getRole('test', true));
|
||||
assertType<APIMessage | Message>(interaction.options.getMessage('test', true));
|
||||
}
|
||||
|
||||
assertType<CommandInteraction>(interaction);
|
||||
|
||||
Reference in New Issue
Block a user