diff --git a/src/commands/applications/chatcontext.ts b/src/commands/applications/chatcontext.ts index f770422..88bde37 100644 --- a/src/commands/applications/chatcontext.ts +++ b/src/commands/applications/chatcontext.ts @@ -214,9 +214,13 @@ export class CommandContext< return this.interaction?.member || ((this.message! as MessageStructure)?.member as any); } - isChat(): this is CommandContext { + isChat(): this is CommandContext { return true; } + + inGuild(): this is GuildCommandContext { + return !!this.guildId; + } } export interface GuildCommandContext diff --git a/src/commands/applications/entrycontext.ts b/src/commands/applications/entrycontext.ts index 47d4d51..9b9db3e 100644 --- a/src/commands/applications/entrycontext.ts +++ b/src/commands/applications/entrycontext.ts @@ -119,6 +119,14 @@ export class EntryPointContext ex get member() { return this.interaction.member; } + + isEntryPoint(): this is EntryPointContext { + return true; + } + + inGuild(): this is GuildEntryPointContext { + return !!this.guildId; + } } export interface GuildEntryPointContext diff --git a/src/commands/applications/menucontext.ts b/src/commands/applications/menucontext.ts index 3b031c3..74fe6a0 100644 --- a/src/commands/applications/menucontext.ts +++ b/src/commands/applications/menucontext.ts @@ -160,6 +160,10 @@ export class MenuCommandContext< isMenuMessage(): this is MenuCommandContext { return this.interaction.data.type === ApplicationCommandType.Message; } + + inGuild(): this is GuildMenuCommandContext { + return !!this.guildId; + } } export interface GuildMenuCommandContext< diff --git a/src/commands/basecontext.ts b/src/commands/basecontext.ts index b9a2974..001a60a 100644 --- a/src/commands/basecontext.ts +++ b/src/commands/basecontext.ts @@ -2,6 +2,7 @@ import type { ModalContext } from '../components'; import type { ComponentContext, ContextComponentCommandInteractionMap } from '../components/componentcontext'; import type { MessageCommandInteraction, UserCommandInteraction } from '../structures'; import type { CommandContext } from './applications/chatcontext'; +import type { EntryPointContext } from './applications/entrycontext'; import type { MenuCommandContext } from './applications/menucontext'; import type { UsingClient } from './applications/shared'; @@ -62,4 +63,8 @@ export class BaseContext { isStringSelectMenu(): this is ComponentContext<'StringSelect'> { return false; } + + isEntryPoint(): this is EntryPointContext { + return false; + } } diff --git a/src/components/componentcontext.ts b/src/components/componentcontext.ts index 486e09c..5d2eba6 100644 --- a/src/components/componentcontext.ts +++ b/src/components/componentcontext.ts @@ -219,29 +219,33 @@ export class ComponentContext< return true; } - isButton(): this is ComponentContext<'Button'> { + isButton(): this is ComponentContext<'Button', M> { return this.interaction.data.componentType === ComponentType.Button; } - isChannelSelectMenu(): this is ComponentContext<'ChannelSelect'> { + isChannelSelectMenu(): this is ComponentContext<'ChannelSelect', M> { return this.interaction.componentType === ComponentType.ChannelSelect; } - isRoleSelectMenu(): this is ComponentContext<'RoleSelect'> { + isRoleSelectMenu(): this is ComponentContext<'RoleSelect', M> { return this.interaction.componentType === ComponentType.RoleSelect; } - isMentionableSelectMenu(): this is ComponentContext<'MentionableSelect'> { + isMentionableSelectMenu(): this is ComponentContext<'MentionableSelect', M> { return this.interaction.componentType === ComponentType.MentionableSelect; } - isUserSelectMenu(): this is ComponentContext<'UserSelect'> { + isUserSelectMenu(): this is ComponentContext<'UserSelect', M> { return this.interaction.componentType === ComponentType.UserSelect; } - isStringSelectMenu(): this is ComponentContext<'StringSelect'> { + isStringSelectMenu(): this is ComponentContext<'StringSelect', M> { return this.interaction.componentType === ComponentType.StringSelect; } + + inGuild(): this is GuildComponentContext { + return !!this.guildId; + } } export interface ContextComponentCommandInteractionMap { @@ -253,8 +257,10 @@ export interface ContextComponentCommandInteractionMap { ChannelSelect: ChannelSelectMenuInteraction; } -export interface GuildComponentContext - extends Omit, 'guildId'>, 'guild'> { +export interface GuildComponentContext< + Type extends keyof ContextComponentCommandInteractionMap, + M extends keyof RegisteredMiddlewares = never, +> extends Omit, 'guildId'>, 'guild'> { guild(mode?: 'rest' | 'flow'): Promise>; guild(mode?: 'cache'): ReturnCache | undefined>; } diff --git a/src/components/modalcontext.ts b/src/components/modalcontext.ts index 7a1f3fd..c4e1c31 100644 --- a/src/components/modalcontext.ts +++ b/src/components/modalcontext.ts @@ -185,9 +185,13 @@ export class ModalContext extends return this.interaction.member; } - isModal(): this is ModalContext { + isModal(): this is ModalContext { return true; } + + inGuild(): this is GuildModalContext { + return !!this.guildId; + } } export interface GuildModalContext