-
-
Notifications
You must be signed in to change notification settings - Fork 4
Using Key Value Load Save
Sporks will allow you to save persistent data to its database, which is isolated and accessible only to events triggered within your guild.
Calling the load()
function will cause the bot to attempt to find a key in its key/value database, for example:
var who_it_was = load("last_user_id");
create_message(CHANNEL_ID, "the last user id was " + who_it_was);
Conversely, calling save()
will save a key to the database:
save("last_user_id", someuser.id);
Note that the key/value store is designed to store singular values. If you want to store an object as a value, you should pass it through JSON.stringify()
to turn it into a string, or when reading it back, use JSON.parse()
:
save("last_user", JSON.stringify(someuser));
var someuser = JSON.parse(load("last_user"));
Please be aware that load()
and save()
can be expensive calls in terms of processing time and can eat into your 10 milliseconds CPU budget per event. Plan out your usage of load()
and save()
to minimise the number of calls to these methods and the amount of data stored.
- The
load()
andsave()
methods save your data to a database which has a limit of 100 key/value pairs per guild. This limitation is in place to prevent any one user from taking up all the disk space. - Each key has a maximum length of 100
- Each value has a maximum length of 65536 bytes, this may not be equal to the number of characters stored if you are storing any international characters, emoji, etc.
- Time spent fetching key/value items from the database still counts towards your 10ms CPU quota.
Access Sporks via the dashboard to apply scripts to your servers. For further help and assistance, you can reach us on discord.
- Brainbox.cc - Developer
- Sporks.gg - Dashboard
- Support Server - Get More Help