Skip to main content

Class: ArgumentStore

The store class which contains AliasPieces.

Hierarchy

Constructors

constructor

new ArgumentStore(): ArgumentStore

Returns

ArgumentStore

Overrides

AliasStore.constructor

Defined in

projects/framework/src/lib/structures/ArgumentStore.ts:5

Properties

#private

Private #private: any

Inherited from

AliasStore.#private

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:413


Constructor

Readonly Constructor: AbstractConstructor<Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.Constructor

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:414


[toStringTag]

Readonly [toStringTag]: string

Inherited from

AliasStore.[toStringTag]

Defined in

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


aliases

Readonly aliases: Collection<string, Argument<unknown, ArgumentOptions>>

The aliases referencing to pieces.

Inherited from

AliasStore.aliases

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:858


constructor

constructor: CollectionConstructor

Inherited from

AliasStore.constructor

Defined in

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


name

Readonly name: "arguments"

Inherited from

AliasStore.name

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:415


paths

Readonly paths: Set<string>

Inherited from

AliasStore.paths

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:416


size

Readonly size: number

Inherited from

AliasStore.size

Defined in

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


strategy

Readonly strategy: ILoaderStrategy<Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.strategy

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:417


[species]

Static Readonly [species]: MapConstructor

Inherited from

AliasStore.[species]

Defined in

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


defaultStrategy

Static defaultStrategy: ILoaderStrategy<any>

The default strategy, defaults to LoaderStrategy, which is constructed on demand when a store is constructed, when none was set beforehand.

Inherited from

AliasStore.defaultStrategy

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:542


logger

Static logger: null | StoreLogger

The default logger, defaults to null.

Inherited from

AliasStore.logger

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:546

Accessors

container

get container(): Container

A reference to the Container object for ease of use.

Returns

Container

See

container

Inherited from

AliasStore.container

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:431

Methods

[iterator]

[iterator](): IterableIterator<[string, Argument<unknown, ArgumentOptions>]>

Returns an iterable of entries in the map.

Returns

IterableIterator<[string, Argument<unknown, ArgumentOptions>]>

Inherited from

AliasStore.[iterator]

Defined in

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


at

at(index): undefined | Argument<unknown, ArgumentOptions>

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 | Argument<unknown, ArgumentOptions>

Inherited from

AliasStore.at

Defined in

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


clear

clear(): void

Returns

void

Inherited from

AliasStore.clear

Defined in

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


clone

clone(): Collection<string, Argument<unknown, ArgumentOptions>>

Creates an identical shallow copy of this collection.

Returns

Collection<string, Argument<unknown, ArgumentOptions>>

Example

const newColl = someColl.clone();

Inherited from

AliasStore.clone

Defined in

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


concat

concat(...collections): Collection<string, Argument<unknown, ArgumentOptions>>

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

Parameters

NameTypeDescription
...collectionsReadonlyCollection<string, Argument<unknown, ArgumentOptions>>[]Collections to merge

Returns

Collection<string, Argument<unknown, ArgumentOptions>>

Example

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

Inherited from

AliasStore.concat

Defined in

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


construct

construct(Ctor, data): Argument<unknown, ArgumentOptions>

Constructs a Piece instance.

Parameters

NameTypeDescription
CtorILoaderResultEntry<Argument<unknown, ArgumentOptions>>The Piece's constructor used to build the instance.
dataHydratedModuleDataThe module's information

Returns

Argument<unknown, ArgumentOptions>

An instance of the constructed piece.

Inherited from

AliasStore.construct

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:518


delete

delete(key): boolean

Parameters

NameType
keystring

Returns

boolean

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

Inherited from

AliasStore.delete

Defined in

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


difference

difference<T>(other): Collection<string, Argument<unknown, ArgumentOptions> | 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<string, T>The other Collection to filter against

Returns

Collection<string, Argument<unknown, ArgumentOptions> | T>

Inherited from

AliasStore.difference

Defined in

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


each

each(fn): ArgumentStore

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

Parameters

NameTypeDescription
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => voidFunction to execute for each element

Returns

ArgumentStore

Example

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

Inherited from

AliasStore.each

Defined in

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

each<T>(fn, thisArg): ArgumentStore

Type parameters

Name
T

Parameters

NameType
fn(this: T, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => void
thisArgT

Returns

ArgumentStore

Inherited from

AliasStore.each

Defined in

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


ensure

ensure(key, defaultValueGenerator): Argument<unknown, ArgumentOptions>

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

Parameters

NameTypeDescription
keystringThe key to get if it exists, or set otherwise
defaultValueGenerator(key: string, collection: ArgumentStore) => Argument<unknown, ArgumentOptions>A function that generates the default value

Returns

Argument<unknown, ArgumentOptions>

Example

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

Inherited from

AliasStore.ensure

Defined in

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


entries

entries(): IterableIterator<[string, Argument<unknown, ArgumentOptions>]>

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

Returns

IterableIterator<[string, Argument<unknown, ArgumentOptions>]>

Inherited from

AliasStore.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<string, Argument<unknown, ArgumentOptions>>Collection to compare with

Returns

boolean

Whether the collections have identical contents

Inherited from

AliasStore.equals

Defined in

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


every

every<K2>(fn): this is Collection<K2, Argument<unknown, ArgumentOptions>>

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

Type parameters

NameType
K2extends string

Parameters

NameTypeDescription
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2Function used to test (should return a boolean)

Returns

this is Collection<K2, Argument<unknown, ArgumentOptions>>

Example

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

Inherited from

AliasStore.every

Defined in

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

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

Type parameters

NameType
V2extends Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2

Returns

this is Collection<string, V2>

Inherited from

AliasStore.every

Defined in

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

every(fn): boolean

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown

Returns

boolean

Inherited from

AliasStore.every

Defined in

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

every<This, K2>(fn, thisArg): this is Collection<K2, Argument<unknown, ArgumentOptions>>

Type parameters

NameType
ThisThis
K2extends string

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2
thisArgThis

Returns

this is Collection<K2, Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.every

Defined in

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

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

Type parameters

NameType
ThisThis
V2extends Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2
thisArgThis

Returns

this is Collection<string, V2>

Inherited from

AliasStore.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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown
thisArgThis

Returns

boolean

Inherited from

AliasStore.every

Defined in

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


filter

filter<K2>(fn): Collection<K2, Argument<unknown, ArgumentOptions>>

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

Type parameters

NameType
K2extends string

Parameters

NameTypeDescription
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2The function to test with (should return boolean)

Returns

Collection<K2, Argument<unknown, ArgumentOptions>>

Example

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

Inherited from

AliasStore.filter

Defined in

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

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

Type parameters

NameType
V2extends Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2

Returns

Collection<string, V2>

Inherited from

AliasStore.filter

Defined in

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

filter(fn): Collection<string, Argument<unknown, ArgumentOptions>>

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown

Returns

Collection<string, Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.filter

Defined in

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

filter<This, K2>(fn, thisArg): Collection<K2, Argument<unknown, ArgumentOptions>>

Type parameters

NameType
ThisThis
K2extends string

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2
thisArgThis

Returns

Collection<K2, Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.filter

Defined in

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

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

Type parameters

NameType
ThisThis
V2extends Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2
thisArgThis

Returns

Collection<string, V2>

Inherited from

AliasStore.filter

Defined in

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

filter<This>(fn, thisArg): Collection<string, Argument<unknown, ArgumentOptions>>

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown
thisArgThis

Returns

Collection<string, Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.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 Argument<unknown, ArgumentOptions>

Parameters

NameTypeDescription
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2The function to test with (should return boolean)

Returns

undefined | V2

Example

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

Inherited from

AliasStore.find

Defined in

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

find(fn): undefined | Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown

Returns

undefined | Argument<unknown, ArgumentOptions>

Inherited from

AliasStore.find

Defined in

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

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

Type parameters

NameType
ThisThis
V2extends Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2
thisArgThis

Returns

undefined | V2

Inherited from

AliasStore.find

Defined in

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

find<This>(fn, thisArg): undefined | Argument<unknown, ArgumentOptions>

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown
thisArgThis

Returns

undefined | Argument<unknown, ArgumentOptions>

Inherited from

AliasStore.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 string

Parameters

NameTypeDescription
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2The function to test with (should return boolean)

Returns

undefined | K2

Example

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

Inherited from

AliasStore.findKey

Defined in

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

findKey(fn): undefined | string

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown

Returns

undefined | string

Inherited from

AliasStore.findKey

Defined in

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

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

Type parameters

NameType
ThisThis
K2extends string

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2
thisArgThis

Returns

undefined | K2

Inherited from

AliasStore.findKey

Defined in

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

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

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown
thisArgThis

Returns

undefined | string

Inherited from

AliasStore.findKey

Defined in

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


first

first(): undefined | Argument<unknown, ArgumentOptions>

Obtains the first value(s) in this collection.

Returns

undefined | Argument<unknown, ArgumentOptions>

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

Inherited from

AliasStore.first

Defined in

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

first(amount): Argument<unknown, ArgumentOptions>[]

Parameters

NameType
amountnumber

Returns

Argument<unknown, ArgumentOptions>[]

Inherited from

AliasStore.first

Defined in

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


firstKey

firstKey(): undefined | string

Obtains the first key(s) in this collection.

Returns

undefined | string

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

Inherited from

AliasStore.firstKey

Defined in

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

firstKey(amount): string[]

Parameters

NameType
amountnumber

Returns

string[]

Inherited from

AliasStore.firstKey

Defined in

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


flatMap

flatMap<T>(fn): Collection<string, 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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => Collection<string, T>Function that produces a new Collection

Returns

Collection<string, T>

Example

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

Inherited from

AliasStore.flatMap

Defined in

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

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

Type parameters

Name
T
This

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => Collection<string, T>
thisArgThis

Returns

Collection<string, T>

Inherited from

AliasStore.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: Argument<unknown, ArgumentOptions>, key: string, map: Map<string, Argument<unknown, ArgumentOptions>>) => void
thisArg?any

Returns

void

Inherited from

AliasStore.forEach

Defined in

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


get

get(key): undefined | Argument<unknown, ArgumentOptions>

Looks up the name by the store, falling back to an alias lookup.

Parameters

NameTypeDescription
keystringThe key to look for.

Returns

undefined | Argument<unknown, ArgumentOptions>

Inherited from

AliasStore.get

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:863


has

has(key): boolean

Checks whether a key is in the store, or is an alias

Parameters

NameTypeDescription
keystringThe key to check

Returns

boolean

Inherited from

AliasStore.has

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:868


hasAll

hasAll(...keys): boolean

Checks if all of the elements exist in the collection.

Parameters

NameTypeDescription
...keysstring[]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

AliasStore.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
...keysstring[]The keys of the elements to check for

Returns

boolean

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

Inherited from

AliasStore.hasAny

Defined in

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


insert

insert(piece): Promise<Argument<unknown, ArgumentOptions>>

Inserts a piece into the store, and adds all the aliases.

Parameters

NameTypeDescription
pieceArgument<unknown, ArgumentOptions>The piece to be inserted into the store.

Returns

Promise<Argument<unknown, ArgumentOptions>>

The inserted piece.

Inherited from

AliasStore.insert

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:880


intersect

intersect<T>(other): Collection<string, 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<string, T>The other Collection to filter against

Returns

Collection<string, T>

Inherited from

AliasStore.intersect

Defined in

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


keyAt

keyAt(index): undefined | string

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 | string

Inherited from

AliasStore.keyAt

Defined in

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


keys

keys(): IterableIterator<string>

Returns an iterable of keys in the map

Returns

IterableIterator<string>

Inherited from

AliasStore.keys

Defined in

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


last

last(): undefined | Argument<unknown, ArgumentOptions>

Obtains the last value(s) in this collection.

Returns

undefined | Argument<unknown, ArgumentOptions>

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

Inherited from

AliasStore.last

Defined in

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

last(amount): Argument<unknown, ArgumentOptions>[]

Parameters

NameType
amountnumber

Returns

Argument<unknown, ArgumentOptions>[]

Inherited from

AliasStore.last

Defined in

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


lastKey

lastKey(): undefined | string

Obtains the last key(s) in this collection.

Returns

undefined | string

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

Inherited from

AliasStore.lastKey

Defined in

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

lastKey(amount): string[]

Parameters

NameType
amountnumber

Returns

string[]

Inherited from

AliasStore.lastKey

Defined in

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


load

load(root, path): Promise<Argument<unknown, ArgumentOptions>[]>

Loads one or more pieces from a path.

Parameters

NameTypeDescription
rootstringThe root directory the file is from.
pathstringThe path of the file to load, relative to the root.

Returns

Promise<Argument<unknown, ArgumentOptions>[]>

All the loaded pieces.

Inherited from

AliasStore.load

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:485


loadAll

loadAll(): Promise<void>

Loads all pieces from all directories specified by paths.

Returns

Promise<void>

Inherited from

AliasStore.loadAll

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:499


loadPiece

loadPiece(entry): Promise<void>

Adds a piece into the store's list of manually registered pieces. If () was called, the piece will be loaded immediately, otherwise it will be queued until () is called.

All manually registered pieces will be kept even after they are loaded to ensure they can be loaded again if () is called again.

Parameters

NameTypeDescription
entryStoreManuallyRegisteredPiece<"arguments">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 always throw a TypeError if entry.piece is not a class.
  • This method will always throw a LoaderError if the piece does not extend the 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.get('commands').loadPiece({
name: 'ping',
piece: PingCommand
});

Inherited from

AliasStore.loadPiece

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:478


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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => TFunction that produces an element of the new array, taking three arguments

Returns

T[]

Example

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

Inherited from

AliasStore.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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => T
thisArgThis

Returns

T[]

Inherited from

AliasStore.map

Defined in

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


mapValues

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

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

Type parameters

Name
T

Parameters

NameTypeDescription
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => TFunction that produces an element of the new collection, taking three arguments

Returns

Collection<string, T>

Example

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

Inherited from

AliasStore.mapValues

Defined in

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

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

Type parameters

Name
This
T

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => T
thisArgThis

Returns

Collection<string, T>

Inherited from

AliasStore.mapValues

Defined in

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


merge

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

Merges two Collections together into a new Collection.

Type parameters

Name
T
R

Parameters

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

Returns

Collection<string, 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

AliasStore.merge

Defined in

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


partition

partition<K2>(fn): [Collection<K2, Argument<unknown, ArgumentOptions>>, Collection<Exclude<string, K2>, Argument<unknown, ArgumentOptions>>]

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 string

Parameters

NameTypeDescription
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2Function used to test (should return a boolean)

Returns

[Collection<K2, Argument<unknown, ArgumentOptions>>, Collection<Exclude<string, K2>, Argument<unknown, ArgumentOptions>>]

Example

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

Inherited from

AliasStore.partition

Defined in

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

partition<V2>(fn): [Collection<string, V2>, Collection<string, Exclude<Argument<unknown, ArgumentOptions>, V2>>]

Type parameters

NameType
V2extends Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2

Returns

[Collection<string, V2>, Collection<string, Exclude<Argument<unknown, ArgumentOptions>, V2>>]

Inherited from

AliasStore.partition

Defined in

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

partition(fn): [Collection<string, Argument<unknown, ArgumentOptions>>, Collection<string, Argument<unknown, ArgumentOptions>>]

Parameters

NameType
fn(value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown

Returns

[Collection<string, Argument<unknown, ArgumentOptions>>, Collection<string, Argument<unknown, ArgumentOptions>>]

Inherited from

AliasStore.partition

Defined in

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

partition<This, K2>(fn, thisArg): [Collection<K2, Argument<unknown, ArgumentOptions>>, Collection<Exclude<string, K2>, Argument<unknown, ArgumentOptions>>]

Type parameters

NameType
ThisThis
K2extends string

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => key is K2
thisArgThis

Returns

[Collection<K2, Argument<unknown, ArgumentOptions>>, Collection<Exclude<string, K2>, Argument<unknown, ArgumentOptions>>]

Inherited from

AliasStore.partition

Defined in

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

partition<This, V2>(fn, thisArg): [Collection<string, V2>, Collection<string, Exclude<Argument<unknown, ArgumentOptions>, V2>>]

Type parameters

NameType
ThisThis
V2extends Argument<unknown, ArgumentOptions>

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => value is V2
thisArgThis

Returns

[Collection<string, V2>, Collection<string, Exclude<Argument<unknown, ArgumentOptions>, V2>>]

Inherited from

AliasStore.partition

Defined in

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

partition<This>(fn, thisArg): [Collection<string, Argument<unknown, ArgumentOptions>>, Collection<string, Argument<unknown, ArgumentOptions>>]

Type parameters

Name
This

Parameters

NameType
fn(this: This, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown
thisArgThis

Returns

[Collection<string, Argument<unknown, ArgumentOptions>>, Collection<string, Argument<unknown, ArgumentOptions>>]

Inherited from

AliasStore.partition

Defined in

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


random

random(): undefined | Argument<unknown, ArgumentOptions>

Obtains unique random value(s) from this collection.

Returns

undefined | Argument<unknown, ArgumentOptions>

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

Inherited from

AliasStore.random

Defined in

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

random(amount): Argument<unknown, ArgumentOptions>[]

Parameters

NameType
amountnumber

Returns

Argument<unknown, ArgumentOptions>[]

Inherited from

AliasStore.random

Defined in

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


randomKey

randomKey(): undefined | string

Obtains unique random key(s) from this collection.

Returns

undefined | string

A single key if no amount is provided or an array

Inherited from

AliasStore.randomKey

Defined in

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

randomKey(amount): string[]

Parameters

NameType
amountnumber

Returns

string[]

Inherited from

AliasStore.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
TArgument<unknown, ArgumentOptions>

Parameters

NameTypeDescription
fn(accumulator: T, value: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => 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

AliasStore.reduce

Defined in

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


registerPath

registerPath(path): ArgumentStore

Registers a directory into the store.

Parameters

NameTypeDescription
pathPathThe path to be added.

Returns

ArgumentStore

Example

store
.registerPath(resolve('commands'))
.registerPath(resolve('third-party', 'commands'));

Inherited from

AliasStore.registerPath

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:442


resolve

resolve(name): Argument<unknown, ArgumentOptions>

Resolves a piece by its name or its instance.

Parameters

NameTypeDescription
namestring | Argument<unknown, ArgumentOptions>The name of the piece or the instance itself.

Returns

Argument<unknown, ArgumentOptions>

The resolved piece.

Inherited from

AliasStore.resolve

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:505


reverse

reverse(): ArgumentStore

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

Returns

ArgumentStore

Inherited from

AliasStore.reverse

Defined in

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


set

set(key, value): ArgumentStore

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
keystring
valueArgument<unknown, ArgumentOptions>

Returns

ArgumentStore

Inherited from

AliasStore.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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknownFunction used to test (should return a boolean)

Returns

boolean

Example

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

Inherited from

AliasStore.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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown
thisArgT

Returns

boolean

Inherited from

AliasStore.some

Defined in

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


sort

sort(compareFunction?): ArgumentStore

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<string, Argument<unknown, ArgumentOptions>>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

ArgumentStore

Example

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

Inherited from

AliasStore.sort

Defined in

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


sorted

sorted(compareFunction?): Collection<string, Argument<unknown, ArgumentOptions>>

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<string, Argument<unknown, ArgumentOptions>>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<string, Argument<unknown, ArgumentOptions>>

Example

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

Inherited from

AliasStore.sorted

Defined in

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


subtract

subtract<T>(other): Collection<string, Argument<unknown, ArgumentOptions>>

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<string, T>The other Collection to filter against

Returns

Collection<string, Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknownFunction used to test (should return a boolean)

Returns

number

The number of removed entries

Inherited from

AliasStore.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: Argument<unknown, ArgumentOptions>, key: string, collection: ArgumentStore) => unknown
thisArgT

Returns

number

Inherited from

AliasStore.sweep

Defined in

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


tap

tap(fn): ArgumentStore

Runs a function on the collection and returns the collection.

Parameters

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

Returns

ArgumentStore

Example

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

Inherited from

AliasStore.tap

Defined in

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

tap<T>(fn, thisArg): ArgumentStore

Type parameters

Name
T

Parameters

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

Returns

ArgumentStore

Inherited from

AliasStore.tap

Defined in

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


toJSON

toJSON(): Argument<unknown, ArgumentOptions>[]

Returns

Argument<unknown, ArgumentOptions>[]

Inherited from

AliasStore.toJSON

Defined in

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


unload

unload(name): Promise<Argument<unknown, ArgumentOptions>>

Unloads a piece given its instance or its name, and removes all the aliases.

Parameters

NameTypeDescription
namestring | Argument<unknown, ArgumentOptions>The name of the file to load.

Returns

Promise<Argument<unknown, ArgumentOptions>>

Returns the piece that was unloaded.

Inherited from

AliasStore.unload

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:874


unloadAll

unloadAll(): Promise<Argument<unknown, ArgumentOptions>[]>

Unloads all pieces from the store.

Returns

Promise<Argument<unknown, ArgumentOptions>[]>

Inherited from

AliasStore.unloadAll

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:495


values

values(): IterableIterator<Argument<unknown, ArgumentOptions>>

Returns an iterable of values in the map

Returns

IterableIterator<Argument<unknown, ArgumentOptions>>

Inherited from

AliasStore.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

AliasStore.combineEntries

Defined in

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