1.0.1 • Published 3 years ago

@smaug-6739/discord-backup v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Discord-backup

A library for simplify the creation of backup system with mongodb database. This module work with discord.js V13

Getting Started

Prerequisites

  • Node.js 16.6.0 or newer is required.

  • Discord.js 13.0.0 or newer is required.

Instalation

With npm :

npm install @smaug-6739/discord-backup

With yarn :

yarn add @smaug-6739/discord-backup

Usage

Import the module from node_modules :

With CommonJS syntax :

const { DiscordBackup } = require("@smaug-6739/discord-backup");

With module syntax :

import { DiscordBackup } = from "@smaug-6739/discord-backup";

Create a new instance of DiscordBackup with the client as a parameter and the database in options :

const backup = new DiscordBackup(client, {
  database: "mongodb://localhost:27017/discord-backup",
});

async DiscordBackup#create(guild)

Create a backup and save it to database.

Parameters :

  • guild : The guild from create the backup (Guild).

Return : The id of the backup (Promise\).

async DiscordBackup#load(guild, options)

Load a backup from database to a specific guild.

Parameters :

  • guild : The guild from load the backup (Guild).
  • options : The options from load the backup (Object).
    • options.id : The id of the backup (Snowflake).
    • options.force : If the bot should delete the old server (Boolean).

Return : Promise\.

Example

const { Client, Intents } = require("discord.js");
const { DiscordBackup } = require("@smaug-6739/discord-backup");
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const backup = new DiscordBackup(client, {
  database: "mongodb://localhost:27017/discord-backup",
});
client.on("messageCreate", async (msg) => {
  const args = msg.content.split(" ");
  if (args[0] === "!create-backup") {
    console.log(await backup.create(msg.guild));
  }
  if (args[0] === "!load-backup") {
    backup.load(msg.guild, {
      id: args[1],
      force: true,
    });
  }
});
client.login("<discord bot token>");

Authors