Skip to main content

Class: StoreRegistry

A strict-typed store registry. This is available in container.

Since

2.1.0

Example

// Adding new stores

// Register the store:
container.stores.register(new RouteStore());

// Augment Sapphire to add the new store, in case of a JavaScript
// project, this can be moved to an `Augments.d.ts` (or any other name)
// file somewhere:
declare module '@sapphire/pieces' {
export interface StoreRegistryEntries {
routes: RouteStore;
}
}

Hierarchy

Constructors

constructor

new StoreRegistry(entries?): StoreRegistry

Parameters

NameType
entries?null | readonly readonly [never, never][]

Returns

StoreRegistry

Inherited from

Collection<StoreRegistryKey, StoreRegistryValue>.constructor

Defined in

node_modules/typescript/lib/lib.es2015.collection.d.ts:50

new StoreRegistry(iterable?): StoreRegistry

Parameters

NameType
iterable?null | Iterable<readonly [never, never]>

Returns

StoreRegistry

Inherited from

Collection<StoreRegistryKey, StoreRegistryValue>.constructor

Defined in

node_modules/typescript/lib/lib.es2015.collection.d.ts:49

node_modules/typescript/lib/lib.es2015.collection.d.ts:50

Properties

#pendingManuallyRegisteredPieces

Private Readonly #pendingManuallyRegisteredPieces: Collection<never, StoreManuallyRegisteredPiece<never>[]>

The queue of pieces to load.

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:35


[toStringTag]

Readonly [toStringTag]: string

Inherited from

Collection.[toStringTag]

Defined in

node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:137


constructor

constructor: CollectionConstructor

Inherited from

Collection.constructor

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:21


size

Readonly size: number

Inherited from

Collection.size

Defined in

node_modules/typescript/lib/lib.es2015.collection.d.ts:45


[species]

Static Readonly [species]: MapConstructor

Inherited from

Collection.[species]

Defined in

node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:319

Methods

[iterator]

[iterator](): IterableIterator<[never, never]>

Returns an iterable of entries in the map.

Returns

IterableIterator<[never, never]>

Inherited from

Collection.[iterator]

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:119


at

at(index): undefined

Identical to Array.at(). Returns the item at a given index, allowing for positive and negative integers. Negative integers count back from the last item in the collection.

Parameters

NameTypeDescription
indexnumberThe index of the element to obtain

Returns

undefined

Inherited from

Collection.at

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:98


clear

clear(): void

Returns

void

Inherited from

Collection.clear

Defined in

node_modules/typescript/lib/lib.es2015.collection.d.ts:20


clone

clone(): Collection<never, never>

Creates an identical shallow copy of this collection.

Returns

Collection<never, never>

Example

const newColl = someColl.clone();

Inherited from

Collection.clone

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:328


concat

concat(...collections): Collection<never, never>

Combines this collection with others into a new collection. None of the source collections are modified.

Parameters

NameTypeDescription
...collectionsReadonlyCollection<never, never>[]Collections to merge

Returns

Collection<never, never>

Example

const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);

Inherited from

Collection.concat

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:338


delete

delete(key): boolean

Parameters

NameType
keynever

Returns

boolean

true if an element in the Map existed and has been removed, or false if the element does not exist.

Inherited from

Collection.delete

Defined in

node_modules/typescript/lib/lib.es2015.collection.d.ts:24


deregister

deregister<T>(store): this

Deregisters a store.

Type parameters

NameType
Textends Piece<PieceOptions, never>

Parameters

NameTypeDescription
storeStore<T, never>The store to deregister.

Returns

this

Since

2.1.0

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:126


difference

difference<T>(other): Collection<never, T>

The difference method returns a new structure containing items where the key is present in one of the original structures but not the other.

Type parameters

Name
T

Parameters

NameTypeDescription
otherReadonlyCollection<never, T>The other Collection to filter against

Returns

Collection<never, T>

Inherited from

Collection.difference

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:378


each

each(fn): this

Identical to Map.forEach(), but returns the collection instead of undefined.

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => voidFunction to execute for each element

Returns

this

Example

collection
.each(user => console.log(user.username))
.filter(user => user.bot)
.each(user => console.log(user.username));

Inherited from

Collection.each

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:303

each<T>(fn, thisArg): this

Type parameters

Name
T

Parameters

NameType
fn(this: T, value: never, key: never, collection: this) => void
thisArgT

Returns

this

Inherited from

Collection.each

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:304


ensure

ensure(key, defaultValueGenerator): never

Obtains the value of the given key if it exists, otherwise sets and returns the value provided by the default value generator.

Parameters

NameTypeDescription
keyneverThe key to get if it exists, or set otherwise
defaultValueGenerator(key: never, collection: this) => neverA function that generates the default value

Returns

never

Example

collection.ensure(guildId, () => defaultGuildConfig);

Inherited from

Collection.ensure

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:41


entries

entries(): IterableIterator<[never, never]>

Returns an iterable of key, value pairs for every entry in the map.

Returns

IterableIterator<[never, never]>

Inherited from

Collection.entries

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:124


equals

equals(collection): boolean

Checks if this collection shares identical items with another. This is different to checking for equality using equal-signs, because the collections may be different objects, but contain the same data.

Parameters

NameTypeDescription
collectionReadonlyCollection<never, never>Collection to compare with

Returns

boolean

Whether the collections have identical contents

Inherited from

Collection.equals

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:347


every

every<K2>(fn): this is Collection<K2, never>

Checks if all items passes a test. Identical in behavior to Array.every().

Type parameters

NameType
K2extends never

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => key is K2Function used to test (should return a boolean)

Returns

this is Collection<K2, never>

Example

collection.every(user => !user.bot);

Inherited from

Collection.every

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:269

every<V2>(fn): this is Collection<never, V2>

Type parameters

NameType
V2extends never

Parameters

NameType
fn(value: never, key: never, collection: this) => value is V2

Returns

this is Collection<never, V2>

Inherited from

Collection.every

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:270

every(fn): boolean

Parameters

NameType
fn(value: never, key: never, collection: this) => unknown

Returns

boolean

Inherited from

Collection.every

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:271

every<This, K2>(fn, thisArg): this is Collection<K2, never>

Type parameters

NameType
ThisThis
K2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => key is K2
thisArgThis

Returns

this is Collection<K2, never>

Inherited from

Collection.every

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:272

every<This, V2>(fn, thisArg): this is Collection<never, V2>

Type parameters

NameType
ThisThis
V2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => value is V2
thisArgThis

Returns

this is Collection<never, V2>

Inherited from

Collection.every

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:273

every<This>(fn, thisArg): boolean

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => unknown
thisArgThis

Returns

boolean

Inherited from

Collection.every

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:274


filter

filter<K2>(fn): Collection<K2, never>

Identical to Array.filter(), but returns a Collection instead of an Array.

Type parameters

NameType
K2extends never

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => key is K2The function to test with (should return boolean)

Returns

Collection<K2, never>

Example

collection.filter(user => user.username === 'Bob');

Inherited from

Collection.filter

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:183

filter<V2>(fn): Collection<never, V2>

Type parameters

NameType
V2extends never

Parameters

NameType
fn(value: never, key: never, collection: this) => value is V2

Returns

Collection<never, V2>

Inherited from

Collection.filter

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:184

filter(fn): Collection<never, never>

Parameters

NameType
fn(value: never, key: never, collection: this) => unknown

Returns

Collection<never, never>

Inherited from

Collection.filter

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:185

filter<This, K2>(fn, thisArg): Collection<K2, never>

Type parameters

NameType
ThisThis
K2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => key is K2
thisArgThis

Returns

Collection<K2, never>

Inherited from

Collection.filter

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:186

filter<This, V2>(fn, thisArg): Collection<never, V2>

Type parameters

NameType
ThisThis
V2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => value is V2
thisArgThis

Returns

Collection<never, V2>

Inherited from

Collection.filter

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:187

filter<This>(fn, thisArg): Collection<never, never>

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => unknown
thisArgThis

Returns

Collection<never, never>

Inherited from

Collection.filter

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:188


find

find<V2>(fn): undefined | V2

Searches for a single item where the given function returns a truthy value. This behaves like Array.find(). All collections used in Discord.js are mapped using their id property, and if you want to find by id you should use the get method. See MDN for details.

Type parameters

NameType
V2extends never

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => value is V2The function to test with (should return boolean)

Returns

undefined | V2

Example

collection.find(user => user.username === 'Bob');

Inherited from

Collection.find

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:142

find(fn): undefined

Parameters

NameType
fn(value: never, key: never, collection: this) => unknown

Returns

undefined

Inherited from

Collection.find

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:143

find<This, V2>(fn, thisArg): undefined | V2

Type parameters

NameType
ThisThis
V2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => value is V2
thisArgThis

Returns

undefined | V2

Inherited from

Collection.find

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:144

find<This>(fn, thisArg): undefined

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => unknown
thisArgThis

Returns

undefined

Inherited from

Collection.find

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:145


findKey

findKey<K2>(fn): undefined | K2

Searches for the key of a single item where the given function returns a truthy value. This behaves like Array.findIndex(), but returns the key rather than the positional index.

Type parameters

NameType
K2extends never

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => key is K2The function to test with (should return boolean)

Returns

undefined | K2

Example

collection.findKey(user => user.username === 'Bob');

Inherited from

Collection.findKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:158

findKey(fn): undefined

Parameters

NameType
fn(value: never, key: never, collection: this) => unknown

Returns

undefined

Inherited from

Collection.findKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:159

findKey<This, K2>(fn, thisArg): undefined | K2

Type parameters

NameType
ThisThis
K2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => key is K2
thisArgThis

Returns

undefined | K2

Inherited from

Collection.findKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:160

findKey<This>(fn, thisArg): undefined

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => unknown
thisArgThis

Returns

undefined

Inherited from

Collection.findKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:161


first

first(): undefined

Obtains the first value(s) in this collection.

Returns

undefined

A single value if no amount is provided or an array of values, starting from the end if amount is negative

Inherited from

Collection.first

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:62

first(amount): never[]

Parameters

NameType
amountnumber

Returns

never[]

Inherited from

Collection.first

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:63


firstKey

firstKey(): undefined

Obtains the first key(s) in this collection.

Returns

undefined

A single key if no amount is provided or an array of keys, starting from the end if amount is negative

Inherited from

Collection.firstKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:71

firstKey(amount): never[]

Parameters

NameType
amountnumber

Returns

never[]

Inherited from

Collection.firstKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:72


flatMap

flatMap<T>(fn): Collection<never, T>

Maps each item into a Collection, then joins the results into a single Collection. Identical in behavior to Array.flatMap().

Type parameters

Name
T

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => Collection<never, T>Function that produces a new Collection

Returns

Collection<never, T>

Example

collection.flatMap(guild => guild.members.cache);

Inherited from

Collection.flatMap

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:217

flatMap<T, This>(fn, thisArg): Collection<never, T>

Type parameters

Name
T
This

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => Collection<never, T>
thisArgThis

Returns

Collection<never, T>

Inherited from

Collection.flatMap

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:218


forEach

forEach(callbackfn, thisArg?): void

Executes a provided function once per each key/value pair in the Map, in insertion order.

Parameters

NameType
callbackfn(value: never, key: never, map: Map<never, never>) => void
thisArg?any

Returns

void

Inherited from

Collection.forEach

Defined in

node_modules/typescript/lib/lib.es2015.collection.d.ts:28


get

get<K>(key): StoreRegistryEntries[K]

Type parameters

NameType
Kextends never

Parameters

NameType
keyK

Returns

StoreRegistryEntries[K]

Inherited from

Collection.get

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:184

get(key): undefined

Parameters

NameType
keystring

Returns

undefined

Inherited from

Collection.get

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:185


has

has(key): true

Parameters

NameType
keynever

Returns

true

Inherited from

Collection.has

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:186

has(key): false

Parameters

NameType
keystring

Returns

false

Inherited from

Collection.has

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:187


hasAll

hasAll(...keys): boolean

Checks if all of the elements exist in the collection.

Parameters

NameTypeDescription
...keysnever[]The keys of the elements to check for

Returns

boolean

true if all of the elements exist, false if at least one does not exist.

Inherited from

Collection.hasAll

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:48


hasAny

hasAny(...keys): boolean

Checks if any of the elements exist in the collection.

Parameters

NameTypeDescription
...keysnever[]The keys of the elements to check for

Returns

boolean

true if any of the elements exist, false if none exist.

Inherited from

Collection.hasAny

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:55


intersect

intersect<T>(other): Collection<never, T>

The intersect method returns a new structure containing items where the keys and values are present in both original structures.

Type parameters

Name
T

Parameters

NameTypeDescription
otherReadonlyCollection<never, T>The other Collection to filter against

Returns

Collection<never, T>

Inherited from

Collection.intersect

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:366


keyAt

keyAt(index): undefined

Identical to Array.at(). Returns the key at a given index, allowing for positive and negative integers. Negative integers count back from the last item in the collection.

Parameters

NameTypeDescription
indexnumberThe index of the key to obtain

Returns

undefined

Inherited from

Collection.keyAt

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:106


keys

keys(): IterableIterator<never>

Returns an iterable of keys in the map

Returns

IterableIterator<never>

Inherited from

Collection.keys

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:129


last

last(): undefined

Obtains the last value(s) in this collection.

Returns

undefined

A single value if no amount is provided or an array of values, starting from the start if amount is negative

Inherited from

Collection.last

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:80

last(amount): never[]

Parameters

NameType
amountnumber

Returns

never[]

Inherited from

Collection.last

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:81


lastKey

lastKey(): undefined

Obtains the last key(s) in this collection.

Returns

undefined

A single key if no amount is provided or an array of keys, starting from the start if amount is negative

Inherited from

Collection.lastKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:89

lastKey(amount): never[]

Parameters

NameType
amountnumber

Returns

never[]

Inherited from

Collection.lastKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:90


load

load(): Promise<void>

Loads all the registered stores.

Returns

Promise<void>

Since

2.1.0

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:41


loadPiece

loadPiece<StoreName>(entry): Promise<void>

If the store was registered, this method will call the store's () loadPiece() method.

If it was called, the entry will be loaded immediately without queueing.

Type parameters

NameType
StoreNameextends never

Parameters

NameTypeDescription
entryStoreManagerManuallyRegisteredPiece<StoreName>The entry to load.

Returns

Promise<void>

Remarks

  • Pieces loaded this way will have their root and path set to VirtualPath, and as such, cannot be reloaded.
  • This method is useful in environments where file system access is limited or unavailable, such as when using Serverless Computing.
  • This method will not throw an error if a store with the given name does not exist, it will simply be queued until it's registered.
  • This method will always throw a TypeError if entry.piece is not a class.
  • If the store is registered, this method will always throw a LoaderError if the piece does not extend the registered store's piece constructor.
  • This operation is atomic, if any of the above errors are thrown, the piece will not be loaded.

Seealso

()

Since

3.8.0

Example

import { container } from '@sapphire/pieces';

class PingCommand extends Command {
// ...
}

container.stores.loadPiece({
store: 'commands',
name: 'ping',
piece: PingCommand
});

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:168


map

map<T>(fn): T[]

Maps each item to another value into an array. Identical in behavior to Array.map().

Type parameters

Name
T

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => TFunction that produces an element of the new array, taking three arguments

Returns

T[]

Example

collection.map(user => user.tag);

Inherited from

Collection.map

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:230

map<This, T>(fn, thisArg): T[]

Type parameters

Name
This
T

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => T
thisArgThis

Returns

T[]

Inherited from

Collection.map

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:231


mapValues

mapValues<T>(fn): Collection<never, T>

Maps each item to another value into a collection. Identical in behavior to Array.map().

Type parameters

Name
T

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => TFunction that produces an element of the new collection, taking three arguments

Returns

Collection<never, T>

Example

collection.mapValues(user => user.tag);

Inherited from

Collection.mapValues

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:243

mapValues<This, T>(fn, thisArg): Collection<never, T>

Type parameters

Name
This
T

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => T
thisArgThis

Returns

Collection<never, T>

Inherited from

Collection.mapValues

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:244


merge

merge<T, R>(other, whenInSelf, whenInOther, whenInBoth): Collection<never, R>

Merges two Collections together into a new Collection.

Type parameters

Name
T
R

Parameters

NameTypeDescription
otherReadonlyCollection<never, T>The other Collection to merge with
whenInSelf(value: never, key: never) => Keep<R>Function getting the result if the entry only exists in this Collection
whenInOther(valueOther: T, key: never) => Keep<R>Function getting the result if the entry only exists in the other Collection
whenInBoth(value: never, valueOther: T, key: never) => Keep<R>Function getting the result if the entry exists in both Collections

Returns

Collection<never, R>

Example

// Sums up the entries in two collections.
coll.merge(
other,
x => ({ keep: true, value: x }),
y => ({ keep: true, value: y }),
(x, y) => ({ keep: true, value: x + y }),
);

Example

// Intersects two collections in a left-biased manner.
coll.merge(
other,
x => ({ keep: false }),
y => ({ keep: false }),
(x, _) => ({ keep: true, value: x }),
);

Inherited from

Collection.merge

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:407


partition

partition<K2>(fn): [Collection<K2, never>, Collection<never, never>]

Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.

Type parameters

NameType
K2extends never

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => key is K2Function used to test (should return a boolean)

Returns

[Collection<K2, never>, Collection<never, never>]

Example

const [big, small] = collection.partition(guild => guild.memberCount > 250);

Inherited from

Collection.partition

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:200

partition<V2>(fn): [Collection<never, V2>, Collection<never, never>]

Type parameters

NameType
V2extends never

Parameters

NameType
fn(value: never, key: never, collection: this) => value is V2

Returns

[Collection<never, V2>, Collection<never, never>]

Inherited from

Collection.partition

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:201

partition(fn): [Collection<never, never>, Collection<never, never>]

Parameters

NameType
fn(value: never, key: never, collection: this) => unknown

Returns

[Collection<never, never>, Collection<never, never>]

Inherited from

Collection.partition

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:202

partition<This, K2>(fn, thisArg): [Collection<K2, never>, Collection<never, never>]

Type parameters

NameType
ThisThis
K2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => key is K2
thisArgThis

Returns

[Collection<K2, never>, Collection<never, never>]

Inherited from

Collection.partition

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:203

partition<This, V2>(fn, thisArg): [Collection<never, V2>, Collection<never, never>]

Type parameters

NameType
ThisThis
V2extends never

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => value is V2
thisArgThis

Returns

[Collection<never, V2>, Collection<never, never>]

Inherited from

Collection.partition

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:204

partition<This>(fn, thisArg): [Collection<never, never>, Collection<never, never>]

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: never, key: never, collection: this) => unknown
thisArgThis

Returns

[Collection<never, never>, Collection<never, never>]

Inherited from

Collection.partition

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:205


random

random(): undefined

Obtains unique random value(s) from this collection.

Returns

undefined

A single value if no amount is provided or an array of values

Inherited from

Collection.random

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:113

random(amount): never[]

Parameters

NameType
amountnumber

Returns

never[]

Inherited from

Collection.random

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:114


randomKey

randomKey(): undefined

Obtains unique random key(s) from this collection.

Returns

undefined

A single key if no amount is provided or an array

Inherited from

Collection.randomKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:121

randomKey(amount): never[]

Parameters

NameType
amountnumber

Returns

never[]

Inherited from

Collection.randomKey

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:122


reduce

reduce<T>(fn, initialValue?): T

Applies a function to produce a single value. Identical in behavior to Array.reduce().

Type parameters

NameType
Tnever

Parameters

NameTypeDescription
fn(accumulator: T, value: never, key: never, collection: this) => TFunction used to reduce, taking four arguments; accumulator, currentValue, currentKey, and collection
initialValue?TStarting value for the accumulator

Returns

T

Example

collection.reduce((acc, guild) => acc + guild.memberCount, 0);

Inherited from

Collection.reduce

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:287


register

register<T>(store): this

Registers a store.

Type parameters

NameType
Textends Piece<PieceOptions, never>

Parameters

NameTypeDescription
storeStore<T, never>The store to register.

Returns

this

Remarks

  • This method will allow StoreRegistry to manage the store, meaning:
  • This will also add all the manually registered pieces by () in the store.

It is generally recommended to register a store as early as possible, before any of the aforementioned methods are called, otherwise you will have to manually call the aforementioned methods for the store to work properly.

If there were manually registered pieces for this store with (), this method will add them to the store and delete the queue. Note, however, that this method will not call the store's () loadPiece() method, and as such, the pieces will not be loaded until () is called.

Since

2.1.0

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:105


registerPath

registerPath(rootDirectory?): void

Registers all user directories from the process working directory, the default value is obtained by assuming CommonJS (high accuracy) but with fallback for ECMAScript Modules (reads package.json's main entry, fallbacks to process.cwd()).

By default, if you have this folder structure:

/home/me/my-bot
├─ src
│ ├─ commands
│ ├─ events
│ └─ main.js
└─ package.json

And you run node src/main.js, the directories /home/me/my-bot/src/commands and /home/me/my-bot/src/events will be registered for the commands and events stores respectively, since both directories are located in the same directory as your main file.

Note: this also registers directories for all other stores, even if they don't have a folder, this allows you to create new pieces and hot-load them later anytime.

Parameters

NameTypeDescription
rootDirectoryPathThe root directory to register pieces at.

Returns

void

Since

2.1.0

Defined in

projects/pieces/src/lib/structures/StoreRegistry.ts:74


reverse

reverse(): this

Identical to Array.reverse() but returns a Collection instead of an Array.

Returns

this

Inherited from

Collection.reverse

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:127


set

set(key, value): this

Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.

Parameters

NameType
keynever
valuenever

Returns

this

Inherited from

Collection.set

Defined in

node_modules/typescript/lib/lib.es2015.collection.d.ts:41


some

some(fn): boolean

Checks if there exists an item that passes a test. Identical in behavior to Array.some().

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => unknownFunction used to test (should return a boolean)

Returns

boolean

Example

collection.some(user => user.discriminator === '0000');

Inherited from

Collection.some

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:256

some<T>(fn, thisArg): boolean

Type parameters

Name
T

Parameters

NameType
fn(this: T, value: never, key: never, collection: this) => unknown
thisArgT

Returns

boolean

Inherited from

Collection.some

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:257


sort

sort(compareFunction?): this

The sort method sorts the items of a collection in place and returns it. The sort is not necessarily stable in Node 10 or older. The default sort order is according to string Unicode code points.

Parameters

NameTypeDescription
compareFunction?Comparator<never, never>Specifies a function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.

Returns

this

Example

collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);

Inherited from

Collection.sort

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:360


sorted

sorted(compareFunction?): Collection<never, never>

The sorted method sorts the items of a collection and returns it. The sort is not necessarily stable in Node 10 or older. The default sort order is according to string Unicode code points.

Parameters

NameTypeDescription
compareFunction?Comparator<never, never>Specifies a function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.

Returns

Collection<never, never>

Example

collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);

Inherited from

Collection.sorted

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:421


subtract

subtract<T>(other): Collection<never, never>

The subtract method returns a new structure containing items where the keys and values of the original structure are not present in the other.

Type parameters

Name
T

Parameters

NameTypeDescription
otherReadonlyCollection<never, T>The other Collection to filter against

Returns

Collection<never, never>

Inherited from

Collection.subtract

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:372


sweep

sweep(fn): number

Removes items that satisfy the provided filter function.

Parameters

NameTypeDescription
fn(value: never, key: never, collection: this) => unknownFunction used to test (should return a boolean)

Returns

number

The number of removed entries

Inherited from

Collection.sweep

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:169

sweep<T>(fn, thisArg): number

Type parameters

Name
T

Parameters

NameType
fn(this: T, value: never, key: never, collection: this) => unknown
thisArgT

Returns

number

Inherited from

Collection.sweep

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:170


tap

tap(fn): this

Runs a function on the collection and returns the collection.

Parameters

NameTypeDescription
fn(collection: this) => voidFunction to execute

Returns

this

Example

collection
.tap(coll => console.log(coll.size))
.filter(user => user.bot)
.tap(coll => console.log(coll.size))

Inherited from

Collection.tap

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:318

tap<T>(fn, thisArg): this

Type parameters

Name
T

Parameters

NameType
fn(this: T, collection: this) => void
thisArgT

Returns

this

Inherited from

Collection.tap

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:319


toJSON

toJSON(): never[]

Returns

never[]

Inherited from

Collection.toJSON

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:422


values

values(): IterableIterator<never>

Returns an iterable of values in the map

Returns

IterableIterator<never>

Inherited from

Collection.values

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:134


combineEntries

combineEntries<K, V>(entries, combine): Collection<K, V>

Creates a Collection from a list of entries.

Type parameters

Name
K
V

Parameters

NameTypeDescription
entriesIterable<[K, V]>The list of entries
combine(firstValue: V, secondValue: V, key: K) => VFunction to combine an existing entry with a new one

Returns

Collection<K, V>

Example

Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
// returns Collection { "a" => 3, "b" => 2 }

Inherited from

Collection.combineEntries

Defined in

node_modules/@discordjs/collection/dist/index.d.ts:435


groupBy

groupBy<K, T>(items, keySelector): Map<K, T[]>

Groups members of an iterable according to the return value of the passed callback.

Type parameters

Name
K
T

Parameters

NameTypeDescription
itemsIterable<T>An iterable.
keySelector(item: T, index: number) => KA callback which will be invoked for each item in items.

Returns

Map<K, T[]>

Inherited from

Collection.groupBy

Defined in

node_modules/typescript/lib/lib.esnext.collection.d.ts:25