UUID¶
IDs so unique, collision odds are basically science fiction.
What is it?¶
UUID generates universally unique identifiers — those long 550e8400-e29b-41d4-a716-446655440000 strings you see everywhere. Use them for session IDs, order references, file keys, or anywhere "probably unique" isn't good enough.
Access it as modules.UUID.
How to use¶
Generate a random UUID:
Both methods are synchronous — no await needed.
Methods¶
| Method | Description |
|---|---|
uuidv4() | Random UUID (most common) |
uuidv6() | Time-ordered UUID (sortable by creation time) |
uuidv4¶
The standard choice — random, collision-resistant:
uuidv6¶
Time-ordered — newer IDs sort after older ones lexicographically. Handy for ordered records:
Try it¶
Short order reference¶
let ref = modules.UUID.uuidv4().slice(0, 8).toUpperCase()
Bot.sendMessage("Your order reference: #" + ref)
Unique file key¶
let fileKey = modules.UUID.uuidv4() + ".json"
db.bot.set("uploads/" + fileKey, { user: user.id, data: params })
Bot.sendMessage("File saved as " + fileKey)
Ordered event log¶
let eventId = modules.UUID.uuidv6()
db.bot.set("events/" + eventId, {
type: "signup",
user: user.id,
at: Date.now()
})
Notes¶
- Sync — no
awaitneeded - Collision-resistant for practical bot use
- No configuration required
- For short random strings (promo codes, PINs), see randomstring
- Official package: uuid on npm