When i am trying to set my welcome channel ID to MongoDB Why my channel last two digit chages to "00"
for example
954226649841430572 --> (when i send to database it changes to) 954226649841430500
my code :
await guild.updateOne(
{ guildID },
{ $set: { leavechannel: channelID } }
);
CodePudding user response:
In MongoDB large numbers can sometimes be cut due to the nature of storing large Ints. Instead of saving the value raw as a number, first use the .toString()
method and store the value as a string. This will eliminate the issue of MongoDB cutting off large Ints and because JS is dynamically typed will have no effect on using the ID as a number once you fetch it from MongoDB.
Similar question answered here about Ints that are too large
Edit: In addition to the large Int issue, Discord.js will parse snowflakes into strings anyways.
From https://discord.com/developers/docs/reference#snowflakes There are some cases in which our API and Gateway may return IDs in an unexpected format. Internally, Discord stores IDs as integer snowflakes. When we serialize IDs to JSON, we transform bigints into strings. Given that all Discord IDs are snowflakes, you should always expect a string.