@ming-suhi/djs-firestore
v0.1.0
Published
A package for managing your Discord bot's structured Firestore.
Downloads
7
Maintainers
Readme
I. About
A package for managing your Discord bot's structured Firestore. For an in-depth documentation visit the documentation website.
II. Getting Started
A. Installing
Run npm install on the command line or terminal.
npm install @ming-suhi/djs-firestore
B. Setting environment
Create a
.env
file in the root directoryPROJECT_ID= CLIENT_EMAIL= PRIVATE_KEY=
Get
project_id
,client_email
, andprivate_key
of your Firebase service account and store it correspondingly.
C. Setting up manager
Require
FirestoreManager
const { FirestoreManager } = require('@ming-suhi/djs-firestore');
Attach an instance to discord client.
client.db = new FirestoreManager();
Initialize guilds.
client.db.initializeGuilds(client);
D. Creating base documents
Listen to
guildCreate
client.on('guildCreate', async guild => { // Code here });
Create guild doc.
// If needed require GuildDocument const { GuildDocument } = = require('@ming-suhi/djs-firestore'); // Check if a guild doc for the guild exist var guildDb = client.db.guilds.get(guild.id); // If not existing create document if (!guildDb) { var guildDb = new GuildDocument(guild.id); guildDb.initialize(); await guildDb.update({id: guild.id, name: guild.name}); // Put a reference to guilds client.db.guilds.set(guild.id, guildDb); }
E. Other methods
Get field method
const guildDb = client.db.guilds.get(guildId); const fieldValue = guildDb.get('fieldName'); console.log(fieldValue);
Update method
const guildDb = client.db.guilds.get(guildId); await guildDb.update({"updated": true});
Delete method
const guildDb = client.db.guilds.get(guildId); await guildDb.delete();
III. Contributing
A. Issues
This project uses GitHub Issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue.
For help and questions about using this project, please open a GitHub issue.
B. Pull requests
Fork the project.
Create a topic branch from master.
Make some commits to improve the project.
Push this branch to your GitHub project.
Open a Pull Request on GitHub.
Discuss, and optionally continue committing.
IV. License
MIT © 明suhi