Skip to main content

Class: DiscordSnowflake

@sapphire/snowflake.DiscordSnowflake

A class for parsing snowflake ids using Discord's snowflake epoch

Which is 2015-01-01 at 00:00:00.000 UTC+0, https://discord.com/developers/docs/reference#snowflakes

Hierarchy

Constructors

constructor

โ€ข new DiscordSnowflake()

Overrides

Snowflake.constructor

Defined in

projects/utilities/packages/snowflake/src/lib/DiscordSnowflake.ts:9

Properties

#epoch

โ€ข Private #epoch: bigint

Internal reference of the epoch passed in the constructor

internal

Inherited from

Snowflake.#epoch

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:17


#increment

โ€ข Private #increment: bigint

Internal incrementor for generating snowflakes

internal

Inherited from

Snowflake.#increment

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:11


decode

โ€ข decode: (id: string | bigint) => DeconstructedSnowflake

Alias for deconstruct

Type declaration

โ–ธ (id): DeconstructedSnowflake

Deconstructs a snowflake given a snowflake ID

example

const epoch = new Date('2000-01-01T00:00:00.000Z');
const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');
Parameters
NameTypeDescription
idstring | bigintthe snowflake to deconstruct
Returns

DeconstructedSnowflake

a deconstructed snowflake

Inherited from

Snowflake.decode

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:23


Epoch

โ–ช Static Readonly Epoch: 1420070400000n

Discord epoch (2015-01-01T00:00:00.000Z)

see https://discord.com/developers/docs/reference#snowflakes

Defined in

projects/utilities/packages/snowflake/src/lib/DiscordSnowflake.ts:17


decode

โ–ช Static decode: (id: string | bigint) => DeconstructedSnowflake = DiscordSnowflake.deconstruct

Type declaration

โ–ธ (id): DeconstructedSnowflake

Deconstructs a snowflake given a snowflake ID

example

const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');
Parameters
NameTypeDescription
idstring | bigintthe snowflake to deconstruct
Returns

DeconstructedSnowflake

a deconstructed snowflake

Defined in

projects/utilities/packages/snowflake/src/lib/DiscordSnowflake.ts:29

Methods

deconstruct

โ–ธ deconstruct(id): DeconstructedSnowflake

Deconstructs a snowflake given a snowflake ID

example

const epoch = new Date('2000-01-01T00:00:00.000Z');
const snowflake = new Snowflake(epoch).deconstruct('3971046231244935168');

Parameters

NameTypeDescription
idstring | bigintthe snowflake to deconstruct

Returns

DeconstructedSnowflake

a deconstructed snowflake

Inherited from

Snowflake.deconstruct

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:79


generate

โ–ธ generate(options?): bigint

Generates a snowflake given an epoch and optionally a timestamp

example

const epoch = new Date('2000-01-01T00:00:00.000Z');
const snowflake = new Snowflake(epoch).generate();

Parameters

NameTypeDescription
optionsSnowflakeGenerateOptionsoptions to pass into the generator, see SnowflakeGenerateOptions note when increment is not provided it defaults to the private increment of the instance

Returns

bigint

A unique snowflake

Inherited from

Snowflake.generate

Defined in

projects/utilities/packages/snowflake/src/lib/Snowflake.ts:44


deconstruct

โ–ธ Static deconstruct(id): DeconstructedSnowflake

Deconstructs a snowflake given a snowflake ID

example

const snowflake = DiscordSnowflake.deconstruct('3971046231244935168');

Parameters

NameTypeDescription
idstring | bigintthe snowflake to deconstruct

Returns

DeconstructedSnowflake

a deconstructed snowflake

Defined in

projects/utilities/packages/snowflake/src/lib/DiscordSnowflake.ts:40


generate

โ–ธ Static generate(options?): bigint

Generates a snowflake given an epoch and optionally a timestamp

example

const snowflake = DiscordSnowflake.generate();

Parameters

NameTypeDescription
optionsSnowflakeGenerateOptionsSnowflakeGenerateOptions to pass into the generator note when increment is not provided it defaults to 0n

Returns

bigint

A unique snowflake

Defined in

projects/utilities/packages/snowflake/src/lib/DiscordSnowflake.ts:55