Preview deployment

class Sweepers

export class Sweepers

A container for all cache sweeping intervals and their associated sweep methods.

Constructors

constructor(
client: Client<true>
)

Constructs a new instance of the Sweepers class

readonly
client : Client

A record of interval timeout that is used to sweep the indicated items, or null if not being swept

options : SweeperOptions

The options the sweepers were instantiated with

static
archivedThreadSweepFilter(
lifetime?: number
) : GlobalSweepFilter<SweeperDefinitions['threads'][0], SweeperDefinitions['threads'][1]>

Creates a sweep filter that sweeps archived threads

destroy() : void

Cancels all sweeping intervals

static
expiredInviteSweepFilter(
lifetime?: number
) : GlobalSweepFilter<SweeperDefinitions['invites'][0], SweeperDefinitions['invites'][1]>

Creates a sweep filter that sweeps expired invites

static
filterByLifetime<

Key

Value

>(
options?: LifetimeFilterOptions<Key, Value>
) : GlobalSweepFilter<Key, Value>

Create a sweepFilter function that uses a lifetime to determine sweepability.

static
outdatedMessageSweepFilter(
lifetime?: number
) : GlobalSweepFilter<SweeperDefinitions['messages'][0], SweeperDefinitions['messages'][1]>

Creates a sweep filter that sweeps outdated messages (edits taken into account)

sweepApplicationCommands(
filter: CollectionSweepFilter<SweeperDefinitions['applicationCommands'][0], SweeperDefinitions['applicationCommands'][1]>
) : number

Sweeps all guild and global application commands and removes the ones which are indicated by the filter.

Returns: Amount of commands that were removed from the caches

sweepAutoModerationRules(
filter: CollectionSweepFilter<SweeperDefinitions['autoModerationRules'][0], SweeperDefinitions['autoModerationRules'][1]>
) : number

Sweeps all auto moderation rules and removes the ones which are indicated by the filter.

Returns: Amount of auto moderation rules that were removed from the caches

sweepBans() : number

Sweeps all guild bans and removes the ones which are indicated by the filter.

Returns: Amount of bans that were removed from the caches

sweepEmojis(
filter: CollectionSweepFilter<SweeperDefinitions['emojis'][0], SweeperDefinitions['emojis'][1]>
) : number

Sweeps all guild emojis and removes the ones which are indicated by the filter.

Returns: Amount of emojis that were removed from the caches

sweepEntitlements(
filter: CollectionSweepFilter<SweeperDefinitions['entitlements'][0], SweeperDefinitions['entitlements'][1]>
) : number

Sweeps all client application entitlements and removes the ones which are indicated by the filter.

Returns: Amount of entitlements that were removed from the caches

sweepGuildMembers(
filter: CollectionSweepFilter<SweeperDefinitions['guildMembers'][0], SweeperDefinitions['guildMembers'][1]>
) : number

Sweeps all guild members and removes the ones which are indicated by the filter. It is highly recommended to keep the client guild member cached

Returns: Amount of guild members that were removed from the caches

sweepInvites(
filter: CollectionSweepFilter<SweeperDefinitions['invites'][0], SweeperDefinitions['invites'][1]>
) : number

Sweeps all guild invites and removes the ones which are indicated by the filter.

Returns: Amount of invites that were removed from the caches

sweepMessages(
filter: CollectionSweepFilter<SweeperDefinitions['messages'][0], SweeperDefinitions['messages'][1]>
) : number

Sweeps all text-based channels' messages and removes the ones which are indicated by the filter.

Examples:
// Remove all messages older than 1800 seconds from the messages cache
const amount = sweepers.sweepMessages(
  Sweepers.filterByLifetime({
    lifetime: 1800,
    getComparisonTimestamp: m => m.editedTimestamp ?? m.createdTimestamp,
  })(),
);
console.log(`Successfully removed ${amount} messages from the cache.`);

Returns: Amount of messages that were removed from the caches

sweepPresences(
filter: CollectionSweepFilter<SweeperDefinitions['presences'][0], SweeperDefinitions['presences'][1]>
) : number

Sweeps all presences and removes the ones which are indicated by the filter.

Returns: Amount of presences that were removed from the caches

sweepReactions(
filter: CollectionSweepFilter<SweeperDefinitions['reactions'][0], SweeperDefinitions['reactions'][1]>
) : number

Sweeps all message reactions and removes the ones which are indicated by the filter.

Returns: Amount of reactions that were removed from the caches

sweepStageInstances(
filter: CollectionSweepFilter<SweeperDefinitions['stageInstances'][0], SweeperDefinitions['stageInstances'][1]>
) : number

Sweeps all guild stage instances and removes the ones which are indicated by the filter.

Returns: Amount of stage instances that were removed from the caches

sweepStickers(
filter: CollectionSweepFilter<SweeperDefinitions['stickers'][0], SweeperDefinitions['stickers'][1]>
) : number

Sweeps all guild stickers and removes the ones which are indicated by the filter.

Returns: Amount of stickers that were removed from the caches

sweepThreadMembers(
filter: CollectionSweepFilter<SweeperDefinitions['threadMembers'][0], SweeperDefinitions['threadMembers'][1]>
) : number

Sweeps all thread members and removes the ones which are indicated by the filter. It is highly recommended to keep the client thread member cached

Returns: Amount of thread members that were removed from the caches

sweepThreads(
filter: CollectionSweepFilter<SweeperDefinitions['threads'][0], SweeperDefinitions['threads'][1]>
) : number

Sweeps all threads and removes the ones which are indicated by the filter.

Examples:
// Remove all threads archived greater than 1 day ago from all the channel caches
const amount = sweepers.sweepThreads(
  Sweepers.filterByLifetime({
    getComparisonTimestamp: t => t.archivedTimestamp,
    excludeFromSweep: t => !t.archived,
  })(),
);
console.log(`Successfully removed ${amount} threads from the cache.`);

Returns: filter Amount of threads that were removed from the caches

sweepUsers() : number

Sweeps all users and removes the ones which are indicated by the filter.

Returns: Amount of users that were removed from the caches

sweepVoiceStates(
filter: CollectionSweepFilter<SweeperDefinitions['voiceStates'][0], SweeperDefinitions['voiceStates'][1]>
) : number

Sweeps all guild voice states and removes the ones which are indicated by the filter.

Returns: Amount of voice states that were removed from the caches