Context: Discord.js utilizes Snowflakes to distinguish between various items such as messages, members, and guilds. In my current situation, I am employing snowflakes as distinct identifiers for members within the guild, serving as the primary key in my MongoDB database.
Challenge: My goal is to integrate Discord's Snowflake as a data type within my Mongoose schema:
import { Snowflake } from 'discord.js';
import { Schema } from 'mongoose';
const MembershipSchema: Schema = new Schema({
discordID: { type: Snowflake, required: true, unique: true },
});
However, I encounter an issue with VSCode's Intellisense indicating that
'Snowflake' is only recognized as a type, not a value in this context.
This discrepancy perplexes me because my understanding based on Discord.js documentation was that Snowflake
functions as a type (essentially representing a string
).
While resorting to using string
instead is a viable solution, I am curious if there exists a method to implement it similarly to the format displayed above. I aim to explicitly specify that the input for the discordID
field must adhere to the Snowflake
criteria, rather than accepting any generic string.