mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
types(Interaction): allow Interaction cached properties to be type narrowed (#6668)
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com> Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { APIInteractionGuildMember } from 'discord-api-types';
|
||||
import { APIGuildMember, APIInteractionGuildMember, APIMessage } from 'discord-api-types/v9';
|
||||
import {
|
||||
ApplicationCommand,
|
||||
ApplicationCommandChannelOption,
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
CommandOptionChoiceResolvableType,
|
||||
CommandOptionNonChoiceResolvableType,
|
||||
Constants,
|
||||
ContextMenuInteraction,
|
||||
DMChannel,
|
||||
Guild,
|
||||
GuildApplicationCommandManager,
|
||||
@@ -856,7 +857,82 @@ declare const booleanValue: boolean;
|
||||
if (interaction.inGuild()) assertType<Snowflake>(interaction.guildId);
|
||||
|
||||
client.on('interactionCreate', async interaction => {
|
||||
if (interaction.inCachedGuild()) {
|
||||
assertType<GuildMember>(interaction.member);
|
||||
} else if (interaction.inRawGuild()) {
|
||||
assertType<APIInteractionGuildMember>(interaction.member);
|
||||
} else {
|
||||
assertType<APIGuildMember | GuildMember | null>(interaction.member);
|
||||
}
|
||||
|
||||
if (interaction.isContextMenu()) {
|
||||
assertType<ContextMenuInteraction>(interaction);
|
||||
if (interaction.inCachedGuild()) {
|
||||
assertType<ContextMenuInteraction>(interaction);
|
||||
assertType<Guild>(interaction.guild);
|
||||
} else if (interaction.inRawGuild()) {
|
||||
assertType<ContextMenuInteraction>(interaction);
|
||||
assertType<null>(interaction.guild);
|
||||
} else if (interaction.inGuild()) {
|
||||
assertType<ContextMenuInteraction>(interaction);
|
||||
assertType<Guild | null>(interaction.guild);
|
||||
}
|
||||
}
|
||||
|
||||
if (interaction.isButton()) {
|
||||
assertType<ButtonInteraction>(interaction);
|
||||
if (interaction.inCachedGuild()) {
|
||||
assertType<ButtonInteraction>(interaction);
|
||||
assertType<Guild>(interaction.guild);
|
||||
} else if (interaction.inRawGuild()) {
|
||||
assertType<ButtonInteraction>(interaction);
|
||||
assertType<null>(interaction.guild);
|
||||
} else if (interaction.inGuild()) {
|
||||
assertType<ButtonInteraction>(interaction);
|
||||
assertType<Guild | null>(interaction.guild);
|
||||
}
|
||||
}
|
||||
|
||||
if (interaction.isMessageComponent()) {
|
||||
assertType<MessageComponentInteraction>(interaction);
|
||||
if (interaction.inCachedGuild()) {
|
||||
assertType<MessageComponentInteraction>(interaction);
|
||||
assertType<Guild>(interaction.guild);
|
||||
} else if (interaction.inRawGuild()) {
|
||||
assertType<MessageComponentInteraction>(interaction);
|
||||
assertType<null>(interaction.guild);
|
||||
} else if (interaction.inGuild()) {
|
||||
assertType<MessageComponentInteraction>(interaction);
|
||||
assertType<Guild | null>(interaction.guild);
|
||||
}
|
||||
}
|
||||
|
||||
if (interaction.isSelectMenu()) {
|
||||
assertType<SelectMenuInteraction>(interaction);
|
||||
if (interaction.inCachedGuild()) {
|
||||
assertType<SelectMenuInteraction>(interaction);
|
||||
assertType<Guild>(interaction.guild);
|
||||
} else if (interaction.inRawGuild()) {
|
||||
assertType<SelectMenuInteraction>(interaction);
|
||||
assertType<null>(interaction.guild);
|
||||
} else if (interaction.inGuild()) {
|
||||
assertType<SelectMenuInteraction>(interaction);
|
||||
assertType<Guild | null>(interaction.guild);
|
||||
}
|
||||
}
|
||||
|
||||
if (interaction.isCommand()) {
|
||||
if (interaction.inRawGuild()) {
|
||||
assertType<CommandInteraction>(interaction);
|
||||
assertType<Promise<APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
} else if (interaction.inCachedGuild()) {
|
||||
assertType<CommandInteraction>(interaction);
|
||||
assertType<Promise<Message>>(interaction.reply({ fetchReply: true }));
|
||||
} else {
|
||||
assertType<CommandInteraction>(interaction);
|
||||
assertType<Promise<Message | APIMessage>>(interaction.reply({ fetchReply: true }));
|
||||
}
|
||||
|
||||
assertType<CommandInteraction>(interaction);
|
||||
assertType<CommandInteractionOptionResolver>(interaction.options);
|
||||
assertType<readonly CommandInteractionOption[]>(interaction.options.data);
|
||||
|
||||
Reference in New Issue
Block a user