Discordio Backup
![versionBadge](https://img.shields.io/npm/v/discordio-backup?style=for-the-badge)
Note: this module uses recent discordjs features and requires discord.js v14.
Discordio Backup is a powerful Node.js module that allows you to easily manage discord server backups.
- Unlimited backups!
- Backup creation takes less than 10 seconds!
- Even restores messages with webhooks!
- And restores everything that is possible to restore (channels, roles, permissions, bans, emojis, name, icon, and more!)
Changelog
- Supports base64 for emojis/icon/banner backup
- New option to save backups in your own database
backup#delete()
removed in favor of backup#remove()
Installation
npm install discordio-backup
Create
Create a backup for the server specified in the parameters!
const backup = require("discordio-backup");
backup.create(Guild, options).then((backupData) => {
console.log(backupData.id);
});
Click here to learn more about backup options.
Load
Allows you to load a backup on a Discord server!
const backup = require("discordio-backup");
backup.load(backupID, Guild).then(() => {
backup.remove(backupID);
});
Fetch
Fetches information from a backup
const backup = require("discordio-backup");
backup.fetch(backupID).then((backupInfos) => {
console.log(backupInfos);
});
Remove
Warn: once the backup is removed, it is impossible to recover it!
const backup = require("discordio-backup");
backup.remove(backupID);
List
Note: backup#list()
simply returns an array of IDs, you must fetch the ID to get complete information.
const backup = require("discordio-backup");
backup.list().then((backups) => {
console.log(backups);
});
SetStorageFolder
Updates the storage folder to another
const backup = require("discordio-backup");
backup.setStorageFolder(__dirname+"/backups/");
await backup.create(guild);
backup.setStorageFolder(__dirname+"/my-backups/");
await backup.create(guild);
Advanced usage
Create [advanced]
You can use more options for backup creation:
const backup = require("discordio-backup");
backup.create(guild, {
maxMessagesPerChannel: 10,
jsonSave: false,
jsonBeautify: true,
doNotBackup: [ "roles", "channels", "emojis", "bans" ],
saveImages: "base64"
});
maxMessagesPerChannel: Maximum of messages to save in each channel. "0" won't save any messages.
jsonSave: Whether to save the backup into a json file. You will have to save the backup data in your own db to load it later.
jsonBeautify: Whether you want your json backup pretty formatted.
doNotBackup: Things you don't want to backup. Available items are: roles
, channels
, emojis
, bans
.
saveImages: How to save images like guild icon and emojis. Set to "url" by default, restoration may not work if the old server is deleted. So, url
is recommended if you want to clone a server (or if you need very light backups), and base64
if you want to backup a server. Save images as base64 creates heavier backups.
Load [advanced]
As you can see, you're able to load a backup from your own data instead of from an ID:
const backup = require("discordio-backup");
backup.load(backupData, guild, {
clearGuildBeforeRestore: true
});
clearGuildBeforeRestore: Whether to clear the guild (roles, channels, etc... will be deleted) before the backup restoration (recommended).
maxMessagesPerChannel: Maximum of messages to restore in each channel. "0" won't restore any messages.
Example Bot
const { Client, PermissionFlagsBits, EmbedBuilder, GatewayIntentBits } = require("discord.js")
const backup = require("discordio-backup")
const client = new Client({ intents: [Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages, Discord.GatewayIntentBits.MessageContent ]})
const settings = {
prefix: "b!",
token: "YOURTOKEN"
};
client.once("ready", () => {
console.log("I'm ready !");
});
client.on("messageCreate", async message => {
let command = message.content.toLowerCase().slice(settings.prefix.length).split(" ")[0];
let args = message.content.split(" ").slice(1);
if (!message.content.startsWith(settings.prefix) || message.author.bot || !message.guild) return;
if(command === "create"){
if(!message.member.permissions.has(Discord.PermissionFlagsBits.Administrator)){
return message.reply(":x: | You must be an administrator of this server to request a backup!");
}
backup.create(message.guild, {
jsonBeautify: true
}).then((backupData) => {
message.author.send("The backup has been created! To load it, type this command on the server of your choice: `"+settings.prefix+"load "+backupData.id+"`!").catch(e => console.error(e));
message.channel.send(":white_check_mark: Backup successfully created. The backup ID was sent in dm!");
});
}
if(command === "load"){
if(!message.member.permissions.has(Discord.PermissionFlagsBits.Administrator)){
return message.reply(":x: | You must be an administrator of this server to load a backup!");
}
let backupID = args[0];
if(!backupID){
return message.channel.send(":x: | You must specify a valid backup ID!");
}
backup.fetch(backupID).then(async () => {
message.channel.send(":warning: | When the backup is loaded, all the channels, roles, etc. will be replaced! Type `-confirm` to confirm!");
const filter = m => (m.author.id === message.author.id) && (m.content === "-confirm");
await message.channel.awaitMessages({
filter,
max: 1,
time: 20000,
errors: ["time"]
}).catch((err) => {
return message.channel.send(":x: | Time's up! Cancelled backup loading!");
});
message.author.send(":white_check_mark: | Start loading the backup!").catch(e => console.error(e));
backup.load(backupID, message.guild).then(() => {
backup.remove(backupID);
}).catch((err) => {
return message.author.send(":x: | Sorry, an error occurred... Please check that I have administrator permissions!");
});
}).catch((err) => {
console.log(err);
return message.channel.send(":x: | No backup found for `"+backupID+"`!");
});
}
if(command === "infos"){
let backupID = args[0];
if(!backupID){
return message.channel.send(":x: | You must specify a valid backup ID!");
}
backup.fetch(backupID).then((backupInfos) => {
const date = new Date(backupInfos.data.createdTimestamp);
const yyyy = date.getFullYear().toString(), mm = (date.getMonth()+1).toString(), dd = date.getDate().toString();
const formatedDate = `${yyyy}/${(mm[1]?mm:"0"+mm[0])}/${(dd[1]?dd:"0"+dd[0])}`;
let embed = new Discord.EmbedBuilder()
.setAuthor({ name: "Backup Informations" })
.addFields(
{ name: 'Backup ID', value: backupInfos.id },
{ name: 'Server ID', value: backupInfos.data.guildID },
{ name: 'Size', value: `${backupInfos.size} kb` },
{ name: 'Created at', value: formatedDate }
)
.setColor(0xFF0000);
message.channel.send({ embeds: [embed] });
}).catch((err) => {
return message.channel.send(":x: | No backup found for `"+backupID+"`!");
});
}
});
client.login(settings.token);
Restored things
Here are all things that can be restored with discordio-backup
:
- Server icon
- Server banner
- Server region
- Server splash
- Server verification level
- Server explicit content filter
- Server default message notifications
- Server embed channel
- Server bans (with reasons)
- Server emojis
- Server AFK (channel and timeout)
- Server channels (with permissions, type, nsfw, messages, etc...)
- Server roles (with permissions, color, etc...)
Example of things that can't be restored:
- Server logs
- Server invitations
- Server vanity url