fix: collect.run types

This commit is contained in:
MARCROCK22 2024-03-27 22:07:39 -04:00
parent 865f863e53
commit 4c05c25a41
3 changed files with 15 additions and 8 deletions

View File

@ -7,11 +7,9 @@ import type { Button } from './Button';
import type { TextInput } from './Modal'; import type { TextInput } from './Modal';
import type { BuilderSelectMenus } from './SelectMenu'; import type { BuilderSelectMenus } from './SelectMenu';
export type ComponentCallback = ( export type ComponentCallback<
interaction: ComponentInteraction | StringSelectMenuInteraction, T extends ComponentInteraction | StringSelectMenuInteraction = ComponentInteraction | StringSelectMenuInteraction,
stop: ComponentStopCallback, > = (interaction: T, stop: ComponentStopCallback, refresh: ComponentRefreshCallback) => any;
refresh: ComponentRefreshCallback,
) => any;
export type ComponentFilterCallback<T = ComponentInteraction> = (interaction: T) => any; export type ComponentFilterCallback<T = ComponentInteraction> = (interaction: T) => any;
export type ComponentStopCallback = (reason?: string, refresh?: ComponentRefreshCallback) => any; export type ComponentStopCallback = (reason?: string, refresh?: ComponentRefreshCallback) => any;
export type ComponentRefreshCallback = () => any; export type ComponentRefreshCallback = () => any;

View File

@ -1,4 +1,4 @@
import type { GatewayVoiceState } from '../../common'; import type { GatewayVoiceState } from 'discord-api-types/v10';
import { GuildBasedResource } from './default/guild-based'; import { GuildBasedResource } from './default/guild-based';
export class VoiceStates extends GuildBasedResource<VoiceStateResource> { export class VoiceStates extends GuildBasedResource<VoiceStateResource> {

View File

@ -2,7 +2,7 @@ import type { ComponentCallback, ListenerOptions, ModalSubmitCallback } from '..
import { LimitedCollection } from '../collection'; import { LimitedCollection } from '../collection';
import type { UsingClient } from '../commands'; import type { UsingClient } from '../commands';
import { BaseHandler, magicImport, type Logger, type OnFailCallback } from '../common'; import { BaseHandler, magicImport, type Logger, type OnFailCallback } from '../common';
import type { ComponentInteraction, ModalSubmitInteraction } from '../structures'; import type { ComponentInteraction, ModalSubmitInteraction, StringSelectMenuInteraction } from '../structures';
import { ComponentCommand, InteractionCommandType, ModalCommand } from './command'; import { ComponentCommand, InteractionCommandType, ModalCommand } from './command';
import { ComponentContext } from './componentcontext'; import { ComponentContext } from './componentcontext';
@ -54,7 +54,15 @@ export class ComponentHandler extends BaseHandler {
super(logger); super(logger);
} }
createComponentCollector(messageId: string, options: ListenerOptions = {}) { createComponentCollector(
messageId: string,
options: ListenerOptions = {},
): {
run<
T extends ComponentInteraction | StringSelectMenuInteraction = ComponentInteraction | StringSelectMenuInteraction,
>(customId: string | string[] | RegExp, callback: ComponentCallback<T>): any;
stop(reason?: string): any;
} {
this.values.set(messageId, { this.values.set(messageId, {
components: [], components: [],
options, options,
@ -85,6 +93,7 @@ export class ComponentHandler extends BaseHandler {
}); });
return { return {
//@ts-expect-error generic
run: this.values.get(messageId)!.__run, run: this.values.get(messageId)!.__run,
stop: (reason?: string) => { stop: (reason?: string) => {
this.deleteValue(messageId); this.deleteValue(messageId);