{"_id":"@antonii1357/discord-backup","name":"@antonii1357/discord-backup","dist-tags":{"latest":"3.3.0"},"versions":{"3.3.0":{"name":"@antonii1357/discord-backup","version":"3.3.0","description":"A complete framework to facilitate server backup using discord.js v12","main":"lib/index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"tsc","format":"prettier --write \"src/**/*.ts\"","lint":"tslint -p tsconfig.json"},"repository":{"type":"git","url":"git+https://github.com/Androz2091/discord-backup.git"},"keywords":["discord","discord.js","backup","clone","bot","discord-backup"],"author":{"name":"antonii1357"},"license":"ISC","bugs":{"url":"https://github.com/Androz2091/discord-backup/issues"},"homepage":"https://github.com/Androz2091/discord-backup#readme","dependencies":{"discord.js":"^14.7.0"},"devDependencies":{"@types/node":"^18.11.9","@types/node-fetch":"^2.6.2","@types/ws":"^8.5.3","prettier":"^2.8.0","tslint":"^6.1.3","tslint-config-prettier":"^1.18.0","typescript":"^4.9.3"},"gitHead":"f332e6f5159d66df701979d713b4ed20cd5203ed","_id":"@antonii1357/discord-backup@3.3.0","_nodeVersion":"18.17.1","_npmVersion":"9.6.2","dist":{"integrity":"sha512-M1UMpFVnd14YFnrtXw/vawO6fW2v6YgK7R5+plUUz+YLlbiFcjibfbxPehoR2m5C4OdyspheBDxtbspRHwMJGQ==","shasum":"efc4bf7b4c5672bc876464b60ede3dd04d01c1f3","tarball":"https://registry.npmjs.org/@antonii1357/discord-backup/-/discord-backup-3.3.0.tgz","fileCount":3,"unpackedSize":12946,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC816cISScX93D2KHWXGlmGpfix5TCuIcVk6xsSYBYsngIgUfWgFhmv5P4CwsiYjEQYMEN0m+dBwT83FopXNlCMZZo="}]},"_npmUser":{"name":"antonii1357","email":"antonii.spam@gmail.com"},"directories":{},"maintainers":[{"name":"antonii1357","email":"antonii.spam@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/discord-backup_3.3.0_1695519772381_0.09856827244026456"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-24T01:42:52.287Z","3.3.0":"2023-09-24T01:42:52.545Z","modified":"2023-09-24T01:42:52.842Z"},"maintainers":[{"name":"antonii1357","email":"antonii.spam@gmail.com"}],"description":"A complete framework to facilitate server backup using discord.js v12","homepage":"https://github.com/Androz2091/discord-backup#readme","keywords":["discord","discord.js","backup","clone","bot","discord-backup"],"repository":{"type":"git","url":"git+https://github.com/Androz2091/discord-backup.git"},"author":{"name":"antonii1357"},"bugs":{"url":"https://github.com/Androz2091/discord-backup/issues"},"license":"ISC","readme":"# Discord Backup\r\n\r\n[![downloadsBadge](https://img.shields.io/npm/dt/discord-backup?style=for-the-badge)](https://npmjs.com/discord-backup)\r\n[![versionBadge](https://img.shields.io/npm/v/discord-backup?style=for-the-badge)](https://npmjs.com/discord-backup)\r\n\r\n**Note**: this module uses recent discordjs features and requires discord.js v13.\r\n\r\nDiscord Backup is a powerful [Node.js](https://nodejs.org) module that allows you to easily manage discord server backups.\r\n\r\n* Unlimited backups!\r\n* Backup creation takes less than 10 seconds!\r\n* Even restores messages with webhooks!\r\n* And restores everything that is possible to restore (channels, roles, permissions, bans, emojis, name, icon, and more!)\r\n\r\n## Changelog\r\n\r\n* Supports base64 for emojis/icon/banner backup\r\n* New option to save backups in your own database\r\n* `backup#delete()` removed in favor of `backup#remove()`\r\n\r\n## Installation\r\n\r\n```js\r\nnpm install --save discord-backup\r\n```\r\n\r\n## Examples\r\n\r\nYou can read this example bot on Github: [backups-bot](https://github.com/Androz2091/backups-bot)\r\n\r\n### Create\r\n\r\nCreate a backup for the server specified in the parameters!\r\n\r\n```js\r\n/**\r\n * @param {Guild} [Guild] - The discord server you want to backup\r\n * @param {object} [options] - The backup options\r\n */\r\n\r\nconst backup = require(\"discord-backup\");\r\nbackup.create(Guild, options).then((backupData) => {\r\n    console.log(backupData.id); // NSJH2\r\n});\r\n```\r\n\r\nClick [here](#create-advanced) to learn more about **backup options**.\r\n\r\n### Load\r\n\r\nAllows you to load a backup on a Discord server!\r\n\r\n```js\r\n/**\r\n * @param {string} [backupID] - The ID of the backup that you want to load\r\n * @param {Guild} [Guild] - The discord server on which you want to load the backup\r\n */\r\n\r\nconst backup = require(\"discord-backup\");\r\nbackup.load(backupID, Guild).then(() => {\r\n    backup.remove(backupID); // When the backup is loaded, it's recommended to delete it\r\n});\r\n```\r\n\r\n### Fetch\r\n\r\nFetches information from a backup\r\n\r\n```js\r\n/**\r\n * @param {string} [backupID] - The ID of the backup to fetch\r\n */\r\n\r\nconst backup = require(\"discord-backup\");\r\nbackup.fetch(backupID).then((backupInfos) => {\r\n    console.log(backupInfos);\r\n    /*\r\n    {\r\n        id: \"BC5qo\",\r\n        size: 0.05\r\n        data: {BackupData}\r\n    }\r\n    */\r\n});\r\n```\r\n\r\n### Remove\r\n\r\n**Warn**: once the backup is removed, it is impossible to recover it!\r\n\r\n```js\r\n/**\r\n * @param {string} [backupID] - The ID of the backup to remove\r\n */\r\n\r\nconst backup = require(\"discord-backup\");\r\nbackup.remove(backupID);\r\n```\r\n\r\n### List\r\n\r\n**Note**: `backup#list()` simply returns an array of IDs, you must fetch the ID to get complete information.\r\n\r\n```js\r\nconst backup = require(\"discord-backup\");\r\nbackup.list().then((backups) => {\r\n    console.log(backups); // Expected Output [ \"BC5qo\", \"Jdo91\", ...]\r\n});\r\n```\r\n\r\n### SetStorageFolder\r\n\r\nUpdates the storage folder to another\r\n\r\n```js\r\nconst backup = require(\"discord-backup\");\r\nbackup.setStorageFolder(__dirname+\"/backups/\");\r\nawait backup.create(guild); // Backup created in ./backups/\r\nbackup.setStorageFolder(__dirname+\"/my-backups/\");\r\nawait backup.create(guild); // Backup created in ./my-backups/\r\n```\r\n\r\n## Advanced usage\r\n\r\n### Create [advanced]\r\n\r\nYou can use more options for backup creation:\r\n\r\n```js\r\nconst backup = require(\"discord-backup\");\r\nbackup.create(guild, {\r\n    maxMessagesPerChannel: 10,\r\n    jsonSave: false,\r\n    jsonBeautify: true,\r\n    doNotBackup: [ \"roles\",  \"channels\", \"emojis\", \"bans\" ],\r\n    saveImages: \"base64\"\r\n});\r\n```\r\n\r\n**maxMessagesPerChannel**: Maximum of messages to save in each channel. \"0\" won't save any messages.  \r\n**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.  \r\n**jsonBeautify**: Whether you want your json backup pretty formatted.  \r\n**doNotBackup**: Things you don't want to backup. Available items are: `roles`, `channels`, `emojis`, `bans`.  \r\n**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.\r\n\r\n### Load [advanced]\r\n\r\nAs you can see, you're able to load a backup from your own data instead of from an ID:\r\n\r\n```js\r\nconst backup = require(\"discord-backup\");\r\nbackup.load(backupData, guild, {\r\n    clearGuildBeforeRestore: true\r\n});\r\n```\r\n\r\n**clearGuildBeforeRestore**: Whether to clear the guild (roles, channels, etc... will be deleted) before the backup restoration (recommended).  \r\n**maxMessagesPerChannel**: Maximum of messages to restore in each channel. \"0\" won't restore any messages.\r\n\r\n## Example Bot\r\n\r\n```js\r\n// Load modules\r\nconst Discord = require(\"discord.js\"),\r\nbackup = require(\"discord-backup\"),\r\nclient = new Discord.Client(),\r\nsettings = {\r\n    prefix: \"b!\",\r\n    token: \"YOURTOKEN\"\r\n};\r\n\r\nclient.on(\"ready\", () => {\r\n    console.log(\"I'm ready !\");\r\n});\r\n\r\nclient.on(\"message\", async message => {\r\n\r\n    // This reads the first part of your message behind your prefix to see which command you want to use.\r\n    let command = message.content.toLowerCase().slice(settings.prefix.length).split(\" \")[0];\r\n\r\n    // These are the arguments behind the commands.\r\n    let args = message.content.split(\" \").slice(1);\r\n\r\n    // If the message does not start with your prefix return.\r\n    // If the user that types a message is a bot account return.\r\n    // If the command comes from DM return.\r\n    if (!message.content.startsWith(settings.prefix) || message.author.bot || !message.guild) return;\r\n\r\n    if(command === \"create\"){\r\n        // Check member permissions\r\n        if(!message.member.hasPermission(\"ADMINISTRATOR\")){\r\n            return message.channel.send(\":x: | You must be an administrator of this server to request a backup!\");\r\n        }\r\n        // Create the backup\r\n        backup.create(message.guild, {\r\n            jsonBeautify: true\r\n        }).then((backupData) => {\r\n            // And send informations to the backup owner\r\n            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+\"`!\");\r\n            message.channel.send(\":white_check_mark: Backup successfully created. The backup ID was sent in dm!\");\r\n        });\r\n    }\r\n\r\n    if(command === \"load\"){\r\n        // Check member permissions\r\n        if(!message.member.hasPermission(\"ADMINISTRATOR\")){\r\n            return message.channel.send(\":x: | You must be an administrator of this server to load a backup!\");\r\n        }\r\n        let backupID = args[0];\r\n        if(!backupID){\r\n            return message.channel.send(\":x: | You must specify a valid backup ID!\");\r\n        }\r\n        // Fetching the backup to know if it exists\r\n        backup.fetch(backupID).then(async () => {\r\n            // If the backup exists, request for confirmation\r\n            message.channel.send(\":warning: | When the backup is loaded, all the channels, roles, etc. will be replaced! Type `-confirm` to confirm!\");\r\n                await message.channel.awaitMessages(m => (m.author.id === message.author.id) && (m.content === \"-confirm\"), {\r\n                    max: 1,\r\n                    time: 20000,\r\n                    errors: [\"time\"]\r\n                }).catch((err) => {\r\n                    // if the author of the commands does not confirm the backup loading\r\n                    return message.channel.send(\":x: | Time's up! Cancelled backup loading!\");\r\n                });\r\n                // When the author of the command has confirmed that he wants to load the backup on his server\r\n                message.author.send(\":white_check_mark: | Start loading the backup!\");\r\n                // Load the backup\r\n                backup.load(backupID, message.guild).then(() => {\r\n                    // When the backup is loaded, delete them from the server\r\n                    backup.remove(backupID);\r\n                }).catch((err) => {\r\n                    // If an error occurred\r\n                    return message.author.send(\":x: | Sorry, an error occurred... Please check that I have administrator permissions!\");\r\n                });\r\n        }).catch((err) => {\r\n            console.log(err);\r\n            // if the backup wasn't found\r\n            return message.channel.send(\":x: | No backup found for `\"+backupID+\"`!\");\r\n        });\r\n    }\r\n\r\n    if(command === \"infos\"){\r\n        let backupID = args[0];\r\n        if(!backupID){\r\n            return message.channel.send(\":x: | You must specify a valid backup ID!\");\r\n        }\r\n        // Fetch the backup\r\n        backup.fetch(backupID).then((backupInfos) => {\r\n            const date = new Date(backupInfos.data.createdTimestamp);\r\n            const yyyy = date.getFullYear().toString(), mm = (date.getMonth()+1).toString(), dd = date.getDate().toString();\r\n            const formatedDate = `${yyyy}/${(mm[1]?mm:\"0\"+mm[0])}/${(dd[1]?dd:\"0\"+dd[0])}`;\r\n            let embed = new Discord.MessageEmbed()\r\n                .setAuthor(\"Backup Informations\")\r\n                // Display the backup ID\r\n                .addField(\"Backup ID\", backupInfos.id, false)\r\n                // Displays the server from which this backup comes\r\n                .addField(\"Server ID\", backupInfos.data.guildID, false)\r\n                // Display the size (in mb) of the backup\r\n                .addField(\"Size\", `${backupInfos.size} kb`, false)\r\n                // Display when the backup was created\r\n                .addField(\"Created at\", formatedDate, false)\r\n                .setColor(\"#FF0000\");\r\n            message.channel.send(embed);\r\n        }).catch((err) => {\r\n            // if the backup wasn't found\r\n            return message.channel.send(\":x: | No backup found for `\"+backupID+\"`!\");\r\n        });\r\n    }\r\n\r\n});\r\n\r\n//Your secret token to log the bot in. (never share this to anyone!)\r\nclient.login(settings.token);\r\n```\r\n\r\n## Restored things\r\n\r\nHere are all things that can be restored with `discord-backup`:  \r\n\r\n* Server icon  \r\n* Server banner  \r\n* Server region  \r\n* Server splash  \r\n* Server verification level  \r\n* Server explicit content filter  \r\n* Server default message notifications  \r\n* Server embed channel  \r\n* Server bans (with reasons)  \r\n* Server emojis  \r\n* Server AFK (channel and timeout)  \r\n* Server channels (with permissions, type, nsfw, messages, etc...)  \r\n* Server roles (with permissions, color, etc...)\r\n\r\nExample of things that can't be restored:\r\n\r\n* Server logs  \r\n* Server invitations  \r\n* Server vanity url\r\n","readmeFilename":"README.md"}