Skip to content

Sweepers

classe · Source

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

Properties

options

options: SweeperOptions

The options the sweepers were instantiated with Source

intervals

intervals: Object<SweeperKey, ?Timeout>

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

Methods

sweepApplicationCommands

sweepApplicationCommands(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which commands will be removed from the caches.

Returns: number — Amount of commands that were removed from the caches Source

sweepAutoModerationRules

sweepAutoModerationRules(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine
which auto moderation rules will be removed from the caches

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

sweepBans

sweepBans(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which bans will be removed from the caches.

Returns: number — Amount of bans that were removed from the caches Source

sweepEmojis

sweepEmojis(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which emojis will be removed from the caches.

Returns: number — Amount of emojis that were removed from the caches Source

sweepInvites

sweepInvites(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which invites will be removed from the caches.

Returns: number — Amount of invites that were removed from the caches Source

sweepGuildMembers

sweepGuildMembers(filter: function): 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 Parameters

NameTypeDescription
filterfunctionThe function used to determine which guild members will be removed from the caches.

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

sweepMessages

sweepMessages(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which messages will be removed from the caches.

Returns: number — Amount of messages that were removed from the caches

js
// 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.`);

Source

sweepPresences

sweepPresences(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which presences will be removed from the caches.

Returns: number — Amount of presences that were removed from the caches Source

sweepReactions

sweepReactions(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which reactions will be removed from the caches.

Returns: number — Amount of reactions that were removed from the caches Source

sweepStageInstances

sweepStageInstances(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which stage instances will be removed from the caches.

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

sweepStickers

sweepStickers(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which stickers will be removed from the caches.

Returns: number — Amount of stickers that were removed from the caches Source

sweepThreadMembers

sweepThreadMembers(filter: function): 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 Parameters

NameTypeDescription
filterfunctionThe function used to determine which thread members will be removed from the caches.

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

sweepThreads

sweepThreads(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which threads will be removed from the caches.

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

js
// 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.`);

Source

sweepUsers

sweepUsers(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which users will be removed from the caches.

Returns: number — Amount of users that were removed from the caches Source

sweepVoiceStates

sweepVoiceStates(filter: function): number

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

NameTypeDescription
filterfunctionThe function used to determine which voice states will be removed from the caches.

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

destroy

destroy(): void

Cancels all sweeping intervals Returns: voidSource

_sweepGuildDirectProp

private

_sweepGuildDirectProp(key: string, filter: function, eventOptions?: SweepEventOptions): Object

Sweep a direct sub property of all guilds Parameters

NameTypeDescription
keystringThe name of the property
filterfunctionFilter function passed to sweep
eventOptions?SweepEventOptionsOptions for the Client event emitted here Default: {}.

Returns: Object — Object containing the number of guilds swept and the number of items swept Source

_validateProperties

private

_validateProperties(key: string)

Validates a set of properties Parameters

NameTypeDescription
keystringKey of the options object to check
Source

_initInterval

private

_initInterval(intervalKey: string, sweepKey: string, opts: Object)

Initialize an interval for sweeping Parameters

NameTypeDescription
intervalKeystringThe name of the property that stores the interval for this sweeper
sweepKeystringThe name of the function that sweeps the desired caches
optsObjectValidated options for a sweep
Source

filterByLifetime

static

filterByLifetime(options?: LifetimeFilterOptions): GlobalSweepFilter

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

NameTypeDescription
options?LifetimeFilterOptionsThe options used to generate the filter function Default: {}.

Returns: GlobalSweepFilterSource

archivedThreadSweepFilter

static

archivedThreadSweepFilter(lifetime?: number): GlobalSweepFilter

Creates a sweep filter that sweeps archived threads Parameters

NameTypeDescription
lifetime?numberHow long a thread has to be archived to be valid for sweeping Default: 14400.

Returns: GlobalSweepFilterSource

expiredInviteSweepFilter

static

expiredInviteSweepFilter(lifetime?: number): GlobalSweepFilter

Creates a sweep filter that sweeps expired invites Parameters

NameTypeDescription
lifetime?numberHow long ago an invite has to have expired to be valid for sweeping Default: 14400.

Returns: GlobalSweepFilterSource

outdatedMessageSweepFilter

static

outdatedMessageSweepFilter(lifetime?: number): GlobalSweepFilter

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

NameTypeDescription
lifetime?numberHow long ago a message has to have been sent or edited to be valid for sweeping Default: 3600.

Returns: GlobalSweepFilterSource

Unofficial software. Not affiliated with or supported by Discord.