Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom database to store backups #148

Closed
FC5570 opened this issue Nov 28, 2020 · 2 comments
Closed

Use custom database to store backups #148

FC5570 opened this issue Nov 28, 2020 · 2 comments

Comments

@FC5570
Copy link

FC5570 commented Nov 28, 2020

The title itself is self explanatory, how can I use something like quick.db to store the backups instead of json as a database?

@wolfier74
Copy link

This is good idea to add it

@Androz2091
Copy link
Owner

Androz2091 commented Jan 2, 2021

Hello 👋
This is already possible!
Example code:

const Discord = require('discord.js');
const client = new Discord.Client();

const backup = require('discord-backup');
const quickdb = require('quick.db');

client.login('your bot token');

const prefix = '!';

client.on('message', async (message) => {

	const args = message.content.slice(prefix).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

	if (command === '!backup') {
	
		const guildData = backup.create(message.guild, {
			jsonSave: false // so the backup won't be saved to a json file
		});

		// guildData is a variable that contains all your backup data!
		// You can store it wherever you want

		// for example, in quick.db
		quickdb.set(`backup_${guildData.id}`, guildData); // for example with quick.db

	}

    if (command === '!load') {
		
		const backupID = args.join(' ');

		// Retrieve backup data from quick.db
		const backupData = quickdb.get(`backup_${backupID}`);

		// and load the backup!
		backup.load(backupData, message.guild);

	}

});

Hope this helps 😉

@Androz2091 Androz2091 pinned this issue Jan 2, 2021
@Androz2091 Androz2091 changed the title How can I use the a custom Database to store backups? Use custom database to store backups Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants