npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

simple-discord.db

v0.3.2

Published

A small library for storing user and guild data in discord bots.

Readme

Simple-discord.db

It is a simple library that can automatically save / check out / modify the saved data of the discord user. The entire file structure is created in the root directory and stores guilds, users, members and other data in a separate file.

Usage

Connect the library as

const DiscordDB = require('simple-discord.db');
const Memory = new DiscordDB("name", Client);

To have access to it through the bot client. The name will determine which DB will be connected. Next, you should perform the initial configuration (performed once).

node node_modules/simple-discord.db create DiscordDB //To the console open in the project folder. DiscordDB - name of DB
//old method
await Memory.create(); //Creates initial files for memory 

All parameters of the database can be configured manually through the config in the folder of this database Example:

{
	autoAdd: true, //Auto add servers and users
	smartAutoAdd: true, //Smart adding users in the database
	backUp: {
		enable: false, //Backups included
		time: 3600000, //Every hour 
		count: 2 //Have at least 2 backups 
	},
	autoSave: {
		enable: true, //Autosave memory 
		lastRefresh: 1637793860575, //Last save time (Not setting)
		time: 1000*60 //Save interval 
	}
}

If you do not use "autoAdd": true you need to write manual addition.An example of adding used in db:

Client.on('messageCreate', message => {
	if(message.guild) {
		if(!Memory.guilds.get(message.guild.id)) Memory.guilds.add(message.guild);
		const memGuild = Memory.guilds.get(message.guild.id,false);
		if(!memGuild.members.get(message.author.id)&&message.member) memGuild.members.add(message.member);
		if(!Memory.users.get(message.author.id)&&message.author) Memory.users.add(message.author);
	}
});

Schemas are needed for this database. The simplest schemes are already automatically created in the memory folder. Their further changes are available when the schema file is changed. Guild Schema File:

module.exports = guild => {
    return  {
        "name": guild.name,
        "owner": guild.ownerId,
        "id": guild.id,
        "members": {}
    };
};

As a guild must have members, members must have a guildId inside for memory to work. These sections of memory can be accessed as Memory.guilds.get(id). In response, you receive data about the guild. The guild itself, like all data inside the memory, has the following keys:

const guild = Memory.guilds.get("899200433552252989");
guild.clearData; //Retrieves a copy of the guild data 
//or
Memory.guilds.clearData; //Retrieves a copy of all guild data in memory 
guild.cache; //Gets this guild's discord cache 
guild.add(message.guild) //Manual Adding Guild to Memory
await guild.fetch(); //Searches for this guild in discord
guild.update(key); //Refreshes / resets a specific tuning key to the default (specified by the schema) 
//or
Memory.guilds.update(key); //Refreshes / resets a specific key for all guilds in memory 

Integration into classes Discord.js

The library can be integrated inside Discord classes.js for easier and more convenient data acquisition. This is done as:

const {Client, Guild, GuildMember, User} = require('discord.js');
const DiscordDB = require('simple-discord.db');

const bot = new Client(config.cfg);
const Memory = new DiscordDB("DiscordDB", bot);
Memory.Discord({Guild, GuildMember, User});

After that, it becomes possible to easily retrieve data from the DB. Example:

const {member, author, guild} = message/interaction;
guild.memory === Memory.guilds.get(guild.id); //true
member.memory === Memory.guilds.get(guild.id).members.get(member.id); //true
author.memory === Memory.users.get(author.id); //true

At the same time, if the smartAutoAdd parameter is activated and the sample is not in the DB, it will be created.

More details

You can output settings data to the console via Memory.console(), but if you want to output data not to the console, but in a simple text format, use Memory.console({clear: true}).

Iterator

You can always call enumeration functions on guilds, users and members objects. Returns the actual value of the content.

for (const iterator of Memory.guilds) {
	console.log(iterator);
}