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

    Interface CooldownConfig<T>

    CooldownConfig

    Cấu hình cooldown cho từng command.

    Ví dụ: cooldown: { duration: 10, scope: "user+role", roleWeights: { VIP_ID: 0.5 }, permissionBypass: PermissionLevel.ADMIN }

    interface CooldownConfig<T extends "message" | "interaction" = "message"> {
        duration: number;
        message?: (
            ms: number,
            ctx: CooldownCommandContext,
            commandName: string,
        ) => CooldownMessageReturn<T>;
        permissionBypass?: PermissionLevel;
        roleWeights?: Record<string, number>;
        scope: CooldownScope | CooldownScope[];
    }

    Type Parameters

    • T extends "message" | "interaction" = "message"
    Index

    Properties

    duration: number

    Thời gian cooldown gốc (seconds)

    Ví dụ: 5 = 5 giây

    message?: (
        ms: number,
        ctx: CooldownCommandContext,
        commandName: string,
    ) => CooldownMessageReturn<T>

    message

    Hàm custom message khi user đang trong cooldown.

    Parameters: ms → thời gian còn lại (seconds) ctx → context của command (interaction/message) commandName → tên command đang chạy

    Return: string hiển thị cho user

    Ví dụ: message: (ms, ctx, name) => Command ${name} còn ${Math.ceil(ms/1000)}s

    permissionBypass?: PermissionLevel

    permissionBypass

    Nếu member có quyền tương ứng → bỏ qua hoàn toàn cooldown

    Ví dụ: permissionBypass: PermissionLevel.ADMIN

    roleWeights?: Record<string, number>

    roleWeights

    Cho phép giảm cooldown dựa trên role.

    Key: roleId Value: multiplier (0 < number ≤ 1)

    Ví dụ: VIP = 0.5 → giảm 50%

    Nếu user có nhiều role được cấu hình: → Lấy weight nhỏ nhất (cooldown ngắn nhất)

    Phạm vi áp dụng cooldown

    Có thể:

    • Một scope
    • Hoặc nhiều scope (array)

    Nếu dùng nhiều scope: → Chỉ cần 1 scope còn hiệu lực là bị block