blackcat.js-discord - v1.0.10
    Preparing search index...

    Interface CreateMessageComponentCollector<ComponentType, InGuild>

    Tùy chọn cấu hình để tạo một Message Component Collector.

    Interface này mở rộng từ MessageCollectorOptionsParams, đồng thời bổ sung:

    • Nguồn collector (source) có thể là Message hoặc ChatInputCommandInteraction
    • Callback onCollector được gọi mỗi khi collector nhận interaction
    • Callback onEnd được gọi khi collector kết thúc

    Đây là type chuẩn để đảm bảo type-safe cho các interaction collector trong hệ thống builder của framework.


    const collector = await builder.createCollector({
    source: message,
    time: 60000,
    onCollector: async (ctx) => {
    console.log(ctx.customId, ctx.userId);
    if (ctx.customId === "confirm") ctx.stop();
    },
    onEnd: (ctx) => {
    console.log(`Collector kết thúc sau ${ctx.total} interactions`);
    }
    });

    MessageCollectorOptionsParams

    interface CreateMessageComponentCollector<
        ComponentType extends MessageComponentType,
        InGuild extends boolean = boolean,
    > {
        componentType?: ComponentType;
        dispose?: boolean;
        filter?: CollectorFilter<
            [
                MappedInteractionTypes<InGuild>[ComponentType],
                Collection<string, MappedInteractionTypes<InGuild>[ComponentType]>,
            ],
        >;
        idle?: number;
        interactionResponse?: InteractionResponse<boolean>;
        max?: number;
        maxComponents?: number;
        maxUsers?: number;
        onCollector: (
            ctx: {
                collector: InteractionCollector<
                    ResolveInteraction<ComponentType, InGuild>,
                >;
                customId: string;
                interaction: ResolveInteraction<ComponentType, InGuild>;
                message: Message;
                stop: () => void;
                userId: string;
                values?: string[];
            },
        ) => any;
        onEnd?: (
            ctx: {
                edit: (
                    options: MessageEditOptions | InteractionReplyOptions,
                ) => Promise<any>;
                message: Message;
                reason: string;
                total: number;
            },
        ) => any;
        source: Message<boolean>
        | ChatInputCommandInteraction<CacheType>;
        time?: number;
    }

    Type Parameters

    • ComponentType extends MessageComponentType

      Loại component (MessageComponentType) mà collector sẽ lắng nghe

    • InGuild extends boolean = boolean

      Xác định collector ở trong guild (true) hay DM (false). Mặc định là boolean.

    Hierarchy

    Index

    Properties

    componentType?: ComponentType
    dispose?: boolean
    filter?: CollectorFilter<
        [
            MappedInteractionTypes<InGuild>[ComponentType],
            Collection<string, MappedInteractionTypes<InGuild>[ComponentType]>,
        ],
    >
    idle?: number
    interactionResponse?: InteractionResponse<boolean>
    max?: number
    maxComponents?: number
    maxUsers?: number
    onCollector: (
        ctx: {
            collector: InteractionCollector<
                ResolveInteraction<ComponentType, InGuild>,
            >;
            customId: string;
            interaction: ResolveInteraction<ComponentType, InGuild>;
            message: Message;
            stop: () => void;
            userId: string;
            values?: string[];
        },
    ) => any

    Callback được gọi mỗi khi collector nhận interaction.

    Type Declaration

      • (
            ctx: {
                collector: InteractionCollector<
                    ResolveInteraction<ComponentType, InGuild>,
                >;
                customId: string;
                interaction: ResolveInteraction<ComponentType, InGuild>;
                message: Message;
                stop: () => void;
                userId: string;
                values?: string[];
            },
        ): any
      • Parameters

        • ctx: {
              collector: InteractionCollector<
                  ResolveInteraction<ComponentType, InGuild>,
              >;
              customId: string;
              interaction: ResolveInteraction<ComponentType, InGuild>;
              message: Message;
              stop: () => void;
              userId: string;
              values?: string[];
          }

          Context chứa thông tin interaction và collector.

          • collector: InteractionCollector<ResolveInteraction<ComponentType, InGuild>>

            Collector instance gốc của discord.js.

          • customId: string

            Custom ID của component.

          • interaction: ResolveInteraction<ComponentType, InGuild>

            Interaction gốc từ Discord.

          • message: Message

            Message chứa component.

          • stop: () => void

            Hàm dừng collector thủ công.

          • userId: string

            ID của user đã thực hiện interaction.

          • Optionalvalues?: string[]

            Giá trị được chọn (chỉ tồn tại với Select Menu).

        Returns any

    onEnd?: (
        ctx: {
            edit: (
                options: MessageEditOptions | InteractionReplyOptions,
            ) => Promise<any>;
            message: Message;
            reason: string;
            total: number;
        },
    ) => any

    Callback được gọi khi collector kết thúc.

    Type Declaration

      • (
            ctx: {
                edit: (
                    options: MessageEditOptions | InteractionReplyOptions,
                ) => Promise<any>;
                message: Message;
                reason: string;
                total: number;
            },
        ): any
      • Parameters

        • ctx: {
              edit: (
                  options: MessageEditOptions | InteractionReplyOptions,
              ) => Promise<any>;
              message: Message;
              reason: string;
              total: number;
          }

          Context chứa thông tin kết thúc collector.

          • edit: (options: MessageEditOptions | InteractionReplyOptions) => Promise<any>

            Helper để chỉnh sửa message gốc.

          • message: Message

            Message chứa component collector.

          • reason: string

            Lý do collector dừng.

            Ví dụ:

            • "time"
            • "idle"
            • "limit"
            • "user"
            • "manual"
          • total: number

            Tổng số interaction collector đã nhận.

        Returns any

    source: Message<boolean> | ChatInputCommandInteraction<CacheType>
    time?: number