Androz2091 / discord-backup

📦 Complete framework to facilitate server backup using discord.js v13

Home Page:https://npmjs.com/package/discord-backup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backup list

LosteX opened this issue · comments

Hello, I've been trying to create a command to list the backups of a member for several days

const { MessageEmbed } = require('discord.js');
const backup = require('discord-backup');
const embed = new MessageEmbed();

exports.run = async (client, message, args) => {

    if(!message.member.hasPermission('ADMINISTRATOR')){
        return message.channel.send('Vous devez avoir les permissions `ADMINISTRATOR` pour créer une sauvegarde.');
    }

const backups = await backup.list()
backups.forEach(async backupID => { 
const backupp = await backup.fetch(backupID)
embed.addField(`Backup : ${backupp.id}`, ""+backupp.data.name+" ("+backupp.data.createdTimestamps+"")
})
}

return : No backup found

i dont think foreach loop is gonna work here, try using for loop

try using this:

const backups = await backup.list()
backups.forEach(async backup => {  // lets do backup instead of backupID
const backupp = await backup.fetch(backup.id) // backup.id is the backup id u r looking for
embed.addField(`Backup : ${backupp.id}`, ""+backupp.data.name+" ("+backupp.data.createdTimestamps+"")
})
}

hey i am using this code see my backup list but I cant see
can someone help me

Try this...

const Discord = require('discord.js');
const backup = require('discord-backup');

exports.run = async (client, message, args) => {

    // If the member doesn't have enough permissions
    if(!message.member.hasPermission('MANAGE_MESSAGES')){
        return message.channel.send(':x: You need to have the manage messages permissions to create a backup in this server.');
    }

    //const backupID = args.join(' ');

    backup.list().then((backups) => {
		
	
		
	backups.forEach((backupID) => {
				
		backup.fetch(backupID).then((backup) => {
			
		const date = new Date(backup.data.createdTimestamp);
        
		const date1 = ('0' + date.getDate()).slice(-2);
		const month = ('0' + (date.getMonth() + 1)).slice(-2);
		const year = date.getFullYear();
		const hours = ('0' + date.getHours()).slice(-2);
		const minutes = ('0' + date.getMinutes()).slice(-2);
		const seconds = ('0' + date.getSeconds()).slice(-2);
		const formattedDate = `${date1}/${month}/${year}, ${hours}:${minutes}:${seconds}`;

        const embed = new Discord.MessageEmbed()
            .setAuthor('ℹ️ Backup', backup.data.iconURL)
            .addField('Server name', backup.data.name)
            .addField('Size', backup.size + ' kb')
            .addField('Created at', formattedDate)
            .setFooter('Backup ID: '+backup.id);
			
			return message.channel.send(embed);
			
		}).catch((err) => {

        if (err === 'No backup found')
            return message.channel.send(':x: No backup found for ID '+backupID+'!');
        else
            return message.channel.send(':x: An error occurred: '+(typeof err === 'string') ? err : JSON.stringify(err));

    });
		
		
		
	});
		
    
	
	
	
	
	//return message.channel.send(backups);
	
	});

};